Skip to content

Commit 19a4bef

Browse files
authored
Support objectLength in Record interface of udf-api (#16946)
1 parent 609bc28 commit 19a4bef

File tree

4 files changed

+28
-0
lines changed
  • iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/access
  • iotdb-core/datanode/src

4 files changed

+28
-0
lines changed

iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/access/Record.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ public interface Record {
124124
*/
125125
Optional<File> getObjectFile(int columnIndex);
126126

127+
/**
128+
* Returns the OBJECT value's real file length at the specified column in this row.
129+
*
130+
* @param columnIndex index of the specified column
131+
* @return length of the object
132+
*/
133+
long objectLength(int columnIndex);
134+
127135
/**
128136
* Returns the Binary representation of an object stored at the specified column in this row.
129137
*

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/function/partition/Slice.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ public Optional<File> getObjectFile(int columnIndex) {
219219
return ObjectTypeUtils.getObjectPathFromBinary(getBinarySafely(columnIndex));
220220
}
221221

222+
@Override
223+
public long objectLength(int columnIndex) {
224+
if (getDataType(columnIndex) != Type.OBJECT) {
225+
throw new UnsupportedOperationException("current column is not object column");
226+
}
227+
Binary binary = getBinarySafely(columnIndex);
228+
return ObjectTypeUtils.getObjectLength(binary);
229+
}
230+
222231
@Override
223232
public Binary readObject(int columnIndex, long offset, int length) {
224233
if (getDataType(columnIndex) != Type.OBJECT) {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/RecordIterator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ public Optional<File> getObjectFile(int columnIndex) {
164164
return ObjectTypeUtils.getObjectPathFromBinary(getBinarySafely(columnIndex));
165165
}
166166

167+
@Override
168+
public long objectLength(int columnIndex) {
169+
if (getDataType(columnIndex) != Type.OBJECT) {
170+
throw new UnsupportedOperationException("current column is not object column");
171+
}
172+
Binary binary = getBinarySafely(columnIndex);
173+
return ObjectTypeUtils.getObjectLength(binary);
174+
}
175+
167176
@Override
168177
public Binary readObject(int columnIndex, long offset, int length) {
169178
if (getDataType(columnIndex) != Type.OBJECT) {

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/function/RecordObjectTypeTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ private void testRecordIterator(Iterator<Record> recordIterator) {
133133
Optional<File> objectFile = record.getObjectFile(0);
134134
assertTrue(objectFile.isPresent());
135135

136+
assertEquals(100L, record.objectLength(0));
137+
136138
assertEquals("(Object) 100 B", record.getString(0));
137139
Assert.assertFalse(recordIterator.hasNext());
138140
}

0 commit comments

Comments
 (0)