Skip to content
Merged
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 @@ -109,7 +109,7 @@ protected BinaryRow getStruct(final int ordinal, final Field field, final int ex
return super.getStruct(ordinal, field, extDataSlot);
}
if (extData[extDataSlot] == null) {
extData[extDataSlot] = DataTypes.createSchema(field);
extData[extDataSlot] = newSchema(field);
}
final BinaryRow row = newRow((Schema) extData[extDataSlot]);
row.pointTo(getBuffer(), getOffset(ordinal), fixedWidth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public static ArrowType toArrowType(DataType foryType) {
return ArrowType.Utf8.INSTANCE;
} else if (foryType instanceof DataTypes.BinaryType) {
return ArrowType.Binary.INSTANCE;
} else if (foryType instanceof DataTypes.FixedWidthBinaryType) {
return new ArrowType.FixedSizeBinary(foryType.byteWidth());
} else if (foryType instanceof DataTypes.DurationType) {
return new ArrowType.Duration(TimeUnit.NANOSECOND);
} else if (foryType instanceof DataTypes.TimestampType) {
Expand Down Expand Up @@ -183,6 +185,8 @@ public static DataType fromArrowType(ArrowType arrowType) {
return DataTypes.utf8();
} else if (arrowType instanceof ArrowType.Binary) {
return DataTypes.binary();
} else if (arrowType instanceof ArrowType.FixedSizeBinary) {
return DataTypes.fixedWidthBinary(((ArrowType.FixedSizeBinary) arrowType).getByteWidth());
} else if (arrowType instanceof ArrowType.Duration) {
return DataTypes.duration();
} else if (arrowType instanceof ArrowType.Timestamp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,19 @@ public String name() {
}
}

/** Raw binary data (fixed-width). */
public static class FixedWidthBinaryType extends FixedWidthType {

private FixedWidthBinaryType(int byteSize) {
super(TYPE_BINARY, byteSize * 8);
}

@Override
public String name() {
return "fixedSizeBinary(" + byteWidth() + ")";
}
}

// ============================================================================
// Temporal types
// ============================================================================
Expand Down Expand Up @@ -614,6 +627,10 @@ public static BinaryType binary() {
return BinaryType.INSTANCE;
}

public static FixedWidthType fixedWidthBinary(int size) {
return new FixedWidthBinaryType(size);
}

public static DurationType duration() {
return DurationType.INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,13 @@ public void testCompactUuidType() {
row.pointTo(buffer, 0, buffer.size());
final CompactUuidType deserializedBean = encoder.fromRow(row);
assertEquals(bean1, deserializedBean);
// Note: Using binary() type which is variable-width, so size includes offset+size header (8
// bytes)
// plus the actual data (16 bytes) plus null bitmap (1 byte) plus alignment = 32 bytes
assertEquals(buffer.size(), 32);
assertEquals(buffer.size(), 17);
}

static class CompactUUIDCodec implements CustomCodec.MemoryBufferCodec<UUID> {
@Override
public Field getForyField(final String fieldName) {
return DataTypes.field(fieldName, DataTypes.binary());
return DataTypes.field(fieldName, DataTypes.fixedWidthBinary(16));
}

@Override
Expand Down Expand Up @@ -293,8 +290,7 @@ public void testInlineNestedArrayType() {
row.pointTo(buffer, 0, buffer.size());
final InlineNestedArrayType deserializedBean = encoder.fromRow(row);
assertEquals(deserializedBean, bean1);
// Size is larger due to variable-width binary encoding for UUIDs
assertEquals(buffer.size(), 109);
assertEquals(buffer.size(), 88);
}

@Data
Expand Down Expand Up @@ -353,8 +349,7 @@ public void testCompactMapType() {
row.pointTo(buffer, 0, buffer.size());
final CompactMapType deserializedBean = encoder.fromRow(row);
assertEquals(deserializedBean, bean1);
// Size is larger due to variable-width binary encoding for UUIDs
assertEquals(buffer.size(), 161);
assertEquals(buffer.size(), 109);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public UUID decode(final MemoryBuffer value) {

@Override
public Field getForyField(final String fieldName) {
return DataTypes.field(fieldName, DataTypes.binary());
return DataTypes.field(fieldName, DataTypes.fixedWidthBinary(16));
}
}

Expand Down
Loading