Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.apache.paimon.types;

import org.apache.paimon.data.Blob;
import org.apache.paimon.data.BlobData;
import org.apache.paimon.data.DataGetters;
import org.apache.paimon.data.InternalArray;
import org.apache.paimon.data.InternalMap;
Expand Down Expand Up @@ -229,7 +231,13 @@ public BiFunction<DataGetters, Integer, Integer> visit(BlobType blobType) {
if (row.isNullAt(index)) {
return NULL_SIZE;
} else {
return Math.toIntExact(row.getVariant(index).sizeInBytes());
Blob blob = row.getBlob(index);
if (blob instanceof BlobData) {
return ((BlobData) blob).toData().length;
} else {
// BlobRef and BlobView
return Math.toIntExact(blob.toDescriptor().length());
}
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.paimon.types;

import org.apache.paimon.data.BinaryString;
import org.apache.paimon.data.Blob;
import org.apache.paimon.data.DataGetters;
import org.apache.paimon.data.Decimal;
import org.apache.paimon.data.GenericArray;
Expand Down Expand Up @@ -192,4 +193,18 @@ void testCalculatorSize() {

Assertions.assertThat(feildSizeCalculator.get(23).apply(row, 23)).isEqualTo(0);
}

@Test
void testBlobSize() {
RowType rowType = RowType.builder().field("b", DataTypes.BLOB()).build();
InternalRowToSizeVisitor visitor = new InternalRowToSizeVisitor();
BiFunction<DataGetters, Integer, Integer> calculator =
rowType.getFieldTypes().get(0).accept(visitor);

GenericRow row = GenericRow.of(Blob.fromData(new byte[] {1, 2, 3}));
Assertions.assertThat(calculator.apply(row, 0)).isEqualTo(3);

GenericRow nullRow = GenericRow.of(new Object[] {null});
Assertions.assertThat(calculator.apply(nullRow, 0)).isEqualTo(0);
}
}
Loading