Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 5 additions & 6 deletions c/src/test/java/org/apache/arrow/c/RoundtripTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,9 @@ public void testEmptyRunEndEncodedVector() {

@Test
public void testExtensionTypeVector() {
ExtensionTypeRegistry.register(new UuidType());
ExtensionTypeRegistry.register(UuidType.INSTANCE);
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 +830,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 @@ -1139,7 +1138,7 @@ public ArrowType deserialize(ArrowType storageType, String serializedData) {
throw new UnsupportedOperationException(
"Cannot construct UuidType from underlying type " + storageType);
}
return new UuidType();
return UuidType.INSTANCE;
}

@Override
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ public void testCopyListVectorWithExtensionType() {
for (int i = 0; i < COUNT; i++) {
listWriter.setPosition(i);
listWriter.startList();
ExtensionWriter extensionWriter = listWriter.extension(new UuidType());
ExtensionWriter extensionWriter = listWriter.extension(UuidType.INSTANCE);
extensionWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter.writeExtension(UUID.randomUUID());
extensionWriter.writeExtension(UUID.randomUUID());
Expand Down Expand Up @@ -896,10 +896,10 @@ public void testCopyMapVectorWithExtensionType() {
mapWriter.setPosition(i);
mapWriter.startMap();
mapWriter.startEntry();
ExtensionWriter extensionKeyWriter = mapWriter.key().extension(new UuidType());
ExtensionWriter extensionKeyWriter = mapWriter.key().extension(UuidType.INSTANCE);
extensionKeyWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionKeyWriter.writeExtension(UUID.randomUUID());
ExtensionWriter extensionValueWriter = mapWriter.value().extension(new UuidType());
ExtensionWriter extensionValueWriter = mapWriter.value().extension(UuidType.INSTANCE);
extensionValueWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionValueWriter.writeExtension(UUID.randomUUID());
mapWriter.endEntry();
Expand Down Expand Up @@ -934,10 +934,10 @@ public void testCopyStructVectorWithExtensionType() {
for (int i = 0; i < COUNT; i++) {
structWriter.setPosition(i);
structWriter.start();
ExtensionWriter extensionWriter1 = structWriter.extension("timestamp1", new UuidType());
ExtensionWriter extensionWriter1 = structWriter.extension("timestamp1", UuidType.INSTANCE);
extensionWriter1.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter1.writeExtension(UUID.randomUUID());
ExtensionWriter extensionWriter2 = structWriter.extension("timestamp2", new UuidType());
ExtensionWriter extensionWriter2 = structWriter.extension("timestamp2", UuidType.INSTANCE);
extensionWriter2.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter2.writeExtension(UUID.randomUUID());
structWriter.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ public void testExtensionType() throws Exception {
try (final NonNullableStructVector container =
NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator);
final UuidVector v =
container.addOrGet("uuid", FieldType.nullable(new UuidType()), UuidVector.class);
container.addOrGet("uuid", FieldType.nullable(UuidType.INSTANCE), UuidVector.class);
final PromotableWriter writer = new PromotableWriter(v, container)) {
UUID u1 = UUID.randomUUID();
UUID u2 = UUID.randomUUID();
Expand All @@ -810,7 +810,8 @@ public void testExtensionType() throws Exception {
public void testExtensionTypeForList() throws Exception {
try (final ListVector container = ListVector.empty(EMPTY_SCHEMA_PATH, allocator);
final UuidVector v =
(UuidVector) container.addOrGetVector(FieldType.nullable(new UuidType())).getVector();
(UuidVector)
container.addOrGetVector(FieldType.nullable(UuidType.INSTANCE)).getVector();
final PromotableWriter writer = new PromotableWriter(v, container)) {
UUID u1 = UUID.randomUUID();
UUID u2 = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,7 @@ public void extensionWriterReader() throws Exception {
StructWriter rootWriter = writer.rootAsStruct();

{
ExtensionWriter extensionWriter = rootWriter.extension("uuid1", new UuidType());
ExtensionWriter extensionWriter = rootWriter.extension("uuid1", UuidType.INSTANCE);
extensionWriter.setPosition(0);
extensionWriter.addExtensionTypeWriterFactory(new UuidWriterFactory());
extensionWriter.writeExtension(u1);
Expand Down
Loading