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
81 changes: 5 additions & 76 deletions c/src/test/java/org/apache/arrow/c/RoundtripTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.memory.util.hash.ArrowBufHasher;
import org.apache.arrow.vector.BaseLargeVariableWidthVector;
import org.apache.arrow.vector.BaseVariableWidthVector;
import org.apache.arrow.vector.BigIntVector;
Expand All @@ -44,7 +43,6 @@
import org.apache.arrow.vector.DateMilliVector;
import org.apache.arrow.vector.DecimalVector;
import org.apache.arrow.vector.DurationVector;
import org.apache.arrow.vector.ExtensionTypeVector;
import org.apache.arrow.vector.FieldVector;
import org.apache.arrow.vector.FixedSizeBinaryVector;
import org.apache.arrow.vector.Float2Vector;
Expand Down Expand Up @@ -74,6 +72,7 @@
import org.apache.arrow.vector.UInt2Vector;
import org.apache.arrow.vector.UInt4Vector;
import org.apache.arrow.vector.UInt8Vector;
import org.apache.arrow.vector.UuidVector;
import org.apache.arrow.vector.ValueVector;
import org.apache.arrow.vector.VarBinaryVector;
import org.apache.arrow.vector.VarCharVector;
Expand All @@ -92,6 +91,7 @@
import org.apache.arrow.vector.complex.StructVector;
import org.apache.arrow.vector.complex.UnionVector;
import org.apache.arrow.vector.complex.impl.UnionMapWriter;
import org.apache.arrow.vector.extension.UuidType;
import org.apache.arrow.vector.holders.IntervalDayHolder;
import org.apache.arrow.vector.holders.NullableLargeVarBinaryHolder;
import org.apache.arrow.vector.holders.NullableUInt4Holder;
Expand All @@ -100,7 +100,6 @@
import org.apache.arrow.vector.types.Types.MinorType;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.ArrowType.ExtensionType;
import org.apache.arrow.vector.types.pojo.ExtensionTypeRegistry;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.types.pojo.Schema;
Expand Down Expand Up @@ -810,9 +809,8 @@ public void testEmptyRunEndEncodedVector() {

@Test
public void testExtensionTypeVector() {
ExtensionTypeRegistry.register(new UuidType());
final Schema schema =
new Schema(Collections.singletonList(Field.nullable("a", new UuidType())));
new Schema(Collections.singletonList(Field.nullable("a", UuidType.INSTANCE)));
try (final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) {
// Fill with data
UUID u1 = UUID.randomUUID();
Expand All @@ -830,13 +828,12 @@ public void testExtensionTypeVector() {
assertEquals(root.getSchema(), importedRoot.getSchema());

final Field field = importedRoot.getSchema().getFields().get(0);
final UuidType expectedType = new UuidType();
assertEquals(
field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME),
expectedType.extensionName());
UuidType.INSTANCE.extensionName());
assertEquals(
field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_METADATA),
expectedType.serialize());
UuidType.INSTANCE.serialize());

final UuidVector deserialized = (UuidVector) importedRoot.getFieldVectors().get(0);
assertEquals(vector.getValueCount(), deserialized.getValueCount());
Expand Down Expand Up @@ -1115,72 +1112,4 @@ private VectorSchemaRoot createTestVSR() {

return new VectorSchemaRoot(fields, vectors);
}

static class UuidType extends ExtensionType {

@Override
public ArrowType storageType() {
return new ArrowType.FixedSizeBinary(16);
}

@Override
public String extensionName() {
return "uuid";
}

@Override
public boolean extensionEquals(ExtensionType other) {
return other instanceof UuidType;
}

@Override
public ArrowType deserialize(ArrowType storageType, String serializedData) {
if (!storageType.equals(storageType())) {
throw new UnsupportedOperationException(
"Cannot construct UuidType from underlying type " + storageType);
}
return new UuidType();
}

@Override
public String serialize() {
return "";
}

@Override
public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocator allocator) {
return new UuidVector(name, allocator, new FixedSizeBinaryVector(name, allocator, 16));
}
}

static class UuidVector extends ExtensionTypeVector<FixedSizeBinaryVector> {

public UuidVector(
String name, BufferAllocator allocator, FixedSizeBinaryVector underlyingVector) {
super(name, allocator, underlyingVector);
}

@Override
public UUID getObject(int index) {
final ByteBuffer bb = ByteBuffer.wrap(getUnderlyingVector().getObject(index));
return new UUID(bb.getLong(), bb.getLong());
}

@Override
public int hashCode(int index) {
return hashCode(index, null);
}

@Override
public int hashCode(int index, ArrowBufHasher hasher) {
return getUnderlyingVector().hashCode(index, hasher);
}

public void set(int index, UUID uuid) {
ByteBuffer bb = ByteBuffer.allocate(16);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
getUnderlyingVector().set(index, bb.array());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class UuidVector extends ExtensionTypeVector<FixedSizeBinaryVector>
public UuidVector(
String name, BufferAllocator allocator, FixedSizeBinaryVector underlyingVector) {
super(name, allocator, underlyingVector);
this.field = new Field(name, FieldType.nullable(new UuidType()), null);
this.field = new Field(name, FieldType.nullable(UuidType.INSTANCE), null);
}

/**
Expand Down Expand Up @@ -99,7 +99,7 @@ public UuidVector(
*/
public UuidVector(String name, BufferAllocator allocator) {
super(name, allocator, new FixedSizeBinaryVector(name, allocator, UUID_BYTE_WIDTH));
this.field = new Field(name, FieldType.nullable(new UuidType()), null);
this.field = new Field(name, FieldType.nullable(UuidType.INSTANCE), null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class UuidType extends ExtensionType {
/** Storage type for UUID: FixedSizeBinary(16). */
public static final ArrowType STORAGE_TYPE = new ArrowType.FixedSizeBinary(UUID_BYTE_WIDTH);

private UuidType() {}

static {
ExtensionTypeRegistry.register(INSTANCE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1208,15 +1208,15 @@ public void testGetTransferPairWithField() {

@Test
public void testListVectorWithExtensionType() throws Exception {
final FieldType type = FieldType.nullable(new UuidType());
final FieldType type = FieldType.nullable(UuidType.INSTANCE);
try (final ListVector inVector = new ListVector("list", allocator, type, null)) {
UnionListWriter writer = inVector.getWriter();
writer.allocate();
writer.setPosition(0);
UUID u1 = UUID.randomUUID();
UUID u2 = UUID.randomUUID();
writer.startList();
ExtensionWriter extensionWriter = writer.extension(new UuidType());
ExtensionWriter extensionWriter = writer.extension(UuidType.INSTANCE);
extensionWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter.writeExtension(u1);
extensionWriter.writeExtension(u2);
Expand All @@ -1236,15 +1236,15 @@ public void testListVectorWithExtensionType() throws Exception {

@Test
public void testListVectorReaderForExtensionType() throws Exception {
final FieldType type = FieldType.nullable(new UuidType());
final FieldType type = FieldType.nullable(UuidType.INSTANCE);
try (final ListVector inVector = new ListVector("list", allocator, type, null)) {
UnionListWriter writer = inVector.getWriter();
writer.allocate();
writer.setPosition(0);
UUID u1 = UUID.randomUUID();
UUID u2 = UUID.randomUUID();
writer.startList();
ExtensionWriter extensionWriter = writer.extension(new UuidType());
ExtensionWriter extensionWriter = writer.extension(UuidType.INSTANCE);
extensionWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter.writeExtension(u1);
extensionWriter.writeExtension(u2);
Expand Down Expand Up @@ -1279,7 +1279,7 @@ public void testCopyFromForExtensionType() throws Exception {
UUID u1 = UUID.randomUUID();
UUID u2 = UUID.randomUUID();
writer.startList();
ExtensionWriter extensionWriter = writer.extension(new UuidType());
ExtensionWriter extensionWriter = writer.extension(UuidType.INSTANCE);
extensionWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter.writeExtension(u1);
extensionWriter.writeExtension(u2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,13 +1284,13 @@ public void testMapVectorWithExtensionType() throws Exception {
writer.startMap();
writer.startEntry();
writer.key().bigInt().writeBigInt(0);
ExtensionWriter extensionWriter = writer.value().extension(new UuidType());
ExtensionWriter extensionWriter = writer.value().extension(UuidType.INSTANCE);
extensionWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter.writeExtension(u1);
writer.endEntry();
writer.startEntry();
writer.key().bigInt().writeBigInt(1);
extensionWriter = writer.value().extension(new UuidType());
extensionWriter = writer.value().extension(UuidType.INSTANCE);
extensionWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter.writeExtension(u2);
writer.endEntry();
Expand Down Expand Up @@ -1326,13 +1326,13 @@ public void testCopyFromForExtensionType() throws Exception {
writer.startMap();
writer.startEntry();
writer.key().bigInt().writeBigInt(0);
ExtensionWriter extensionWriter = writer.value().extension(new UuidType());
ExtensionWriter extensionWriter = writer.value().extension(UuidType.INSTANCE);
extensionWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter.writeExtension(u1);
writer.endEntry();
writer.startEntry();
writer.key().bigInt().writeBigInt(1);
extensionWriter = writer.value().extension(new UuidType());
extensionWriter = writer.value().extension(UuidType.INSTANCE);
extensionWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter.writeExtension(u2);
writer.endEntry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public void testGetTransferPairWithFieldAndCallBack() {

@Test
public void testStructVectorWithExtensionTypes() {
UuidType uuidType = new UuidType();
UuidType uuidType = UuidType.INSTANCE;
Field uuidField = new Field("struct_child", FieldType.nullable(uuidType), null);
Field structField =
new Field("struct", FieldType.nullable(new ArrowType.Struct()), List.of(uuidField));
Expand All @@ -353,7 +353,7 @@ public void testStructVectorWithExtensionTypes() {

@Test
public void testStructVectorTransferPairWithExtensionType() {
UuidType uuidType = new UuidType();
UuidType uuidType = UuidType.INSTANCE;
Field uuidField = new Field("uuid_child", FieldType.nullable(uuidType), null);
Field structField =
new Field("struct", FieldType.nullable(new ArrowType.Struct()), List.of(uuidField));
Expand Down
26 changes: 13 additions & 13 deletions vector/src/test/java/org/apache/arrow/vector/TestUuidType.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ void testConstants() {

@Test
void testStorageType() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
assertEquals(UuidType.STORAGE_TYPE, type.storageType());
assertInstanceOf(ArrowType.FixedSizeBinary.class, type.storageType());
}

@Test
void testExtensionName() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
assertEquals("arrow.uuid", type.extensionName());
}

@Test
void testExtensionEquals() {
UuidType type1 = new UuidType();
UuidType type2 = new UuidType();
UuidType type1 = UuidType.INSTANCE;
UuidType type2 = UuidType.INSTANCE;
UuidType type3 = UuidType.INSTANCE;

assertTrue(type1.extensionEquals(type2));
Expand All @@ -99,20 +99,20 @@ void testExtensionEquals() {

@Test
void testIsComplex() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
assertFalse(type.isComplex());
}

@Test
void testSerialize() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
String serialized = type.serialize();
assertEquals("", serialized);
}

@Test
void testDeserializeValid() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
ArrowType storageType = new ArrowType.FixedSizeBinary(UuidType.UUID_BYTE_WIDTH);

ArrowType deserialized = assertDoesNotThrow(() -> type.deserialize(storageType, ""));
Expand All @@ -122,15 +122,15 @@ void testDeserializeValid() {

@Test
void testDeserializeInvalidStorageType() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
ArrowType wrongStorageType = new ArrowType.FixedSizeBinary(32);

assertThrows(UnsupportedOperationException.class, () -> type.deserialize(wrongStorageType, ""));
}

@Test
void testGetNewVector() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
try (FieldVector vector =
type.getNewVector("uuid_field", FieldType.nullable(type), allocator)) {
assertInstanceOf(UuidVector.class, vector);
Expand All @@ -141,7 +141,7 @@ void testGetNewVector() {

@Test
void testVectorOperations() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
try (FieldVector vector =
type.getNewVector("uuid_field", FieldType.nullable(type), allocator)) {
UuidVector uuidVector = (UuidVector) vector;
Expand Down Expand Up @@ -218,7 +218,7 @@ void testVectorIpcRoundTrip() throws IOException {

@Test
void testVectorByteArrayOperations() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
try (FieldVector vector =
type.getNewVector("uuid_field", FieldType.nullable(type), allocator)) {
UuidVector uuidVector = (UuidVector) vector;
Expand All @@ -240,7 +240,7 @@ void testVectorByteArrayOperations() {

@Test
void testGetNewVectorWithCustomFieldType() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
FieldType fieldType = new FieldType(false, type, null);

try (FieldVector vector = type.getNewVector("non_nullable_uuid", fieldType, allocator)) {
Expand All @@ -262,7 +262,7 @@ void testSingleton() {

@Test
void testUnderlyingVector() {
UuidType type = new UuidType();
UuidType type = UuidType.INSTANCE;
try (FieldVector vector =
type.getNewVector("uuid_field", FieldType.nullable(type), allocator)) {
UuidVector uuidVector = (UuidVector) vector;
Expand Down
Loading
Loading