3535import org .apache .arrow .memory .ArrowBuf ;
3636import org .apache .arrow .memory .BufferAllocator ;
3737import org .apache .arrow .memory .RootAllocator ;
38- import org .apache .arrow .memory .util .hash .ArrowBufHasher ;
3938import org .apache .arrow .vector .BaseLargeVariableWidthVector ;
4039import org .apache .arrow .vector .BaseVariableWidthVector ;
4140import org .apache .arrow .vector .BigIntVector ;
4443import org .apache .arrow .vector .DateMilliVector ;
4544import org .apache .arrow .vector .DecimalVector ;
4645import org .apache .arrow .vector .DurationVector ;
47- import org .apache .arrow .vector .ExtensionTypeVector ;
4846import org .apache .arrow .vector .FieldVector ;
4947import org .apache .arrow .vector .FixedSizeBinaryVector ;
5048import org .apache .arrow .vector .Float2Vector ;
7472import org .apache .arrow .vector .UInt2Vector ;
7573import org .apache .arrow .vector .UInt4Vector ;
7674import org .apache .arrow .vector .UInt8Vector ;
75+ import org .apache .arrow .vector .UuidVector ;
7776import org .apache .arrow .vector .ValueVector ;
7877import org .apache .arrow .vector .VarBinaryVector ;
7978import org .apache .arrow .vector .VarCharVector ;
9291import org .apache .arrow .vector .complex .StructVector ;
9392import org .apache .arrow .vector .complex .UnionVector ;
9493import org .apache .arrow .vector .complex .impl .UnionMapWriter ;
94+ import org .apache .arrow .vector .extension .UuidType ;
9595import org .apache .arrow .vector .holders .IntervalDayHolder ;
9696import org .apache .arrow .vector .holders .NullableLargeVarBinaryHolder ;
9797import org .apache .arrow .vector .holders .NullableUInt4Holder ;
100100import org .apache .arrow .vector .types .Types .MinorType ;
101101import org .apache .arrow .vector .types .pojo .ArrowType ;
102102import org .apache .arrow .vector .types .pojo .ArrowType .ExtensionType ;
103- import org .apache .arrow .vector .types .pojo .ExtensionTypeRegistry ;
104103import org .apache .arrow .vector .types .pojo .Field ;
105104import org .apache .arrow .vector .types .pojo .FieldType ;
106105import org .apache .arrow .vector .types .pojo .Schema ;
@@ -810,9 +809,8 @@ public void testEmptyRunEndEncodedVector() {
810809
811810 @ Test
812811 public void testExtensionTypeVector () {
813- ExtensionTypeRegistry .register (new UuidType ());
814812 final Schema schema =
815- new Schema (Collections .singletonList (Field .nullable ("a" , new UuidType () )));
813+ new Schema (Collections .singletonList (Field .nullable ("a" , UuidType . INSTANCE )));
816814 try (final VectorSchemaRoot root = VectorSchemaRoot .create (schema , allocator )) {
817815 // Fill with data
818816 UUID u1 = UUID .randomUUID ();
@@ -830,13 +828,12 @@ public void testExtensionTypeVector() {
830828 assertEquals (root .getSchema (), importedRoot .getSchema ());
831829
832830 final Field field = importedRoot .getSchema ().getFields ().get (0 );
833- final UuidType expectedType = new UuidType ();
834831 assertEquals (
835832 field .getMetadata ().get (ExtensionType .EXTENSION_METADATA_KEY_NAME ),
836- expectedType .extensionName ());
833+ UuidType . INSTANCE .extensionName ());
837834 assertEquals (
838835 field .getMetadata ().get (ExtensionType .EXTENSION_METADATA_KEY_METADATA ),
839- expectedType .serialize ());
836+ UuidType . INSTANCE .serialize ());
840837
841838 final UuidVector deserialized = (UuidVector ) importedRoot .getFieldVectors ().get (0 );
842839 assertEquals (vector .getValueCount (), deserialized .getValueCount ());
@@ -1115,72 +1112,4 @@ private VectorSchemaRoot createTestVSR() {
11151112
11161113 return new VectorSchemaRoot (fields , vectors );
11171114 }
1118-
1119- static class UuidType extends ExtensionType {
1120-
1121- @ Override
1122- public ArrowType storageType () {
1123- return new ArrowType .FixedSizeBinary (16 );
1124- }
1125-
1126- @ Override
1127- public String extensionName () {
1128- return "uuid" ;
1129- }
1130-
1131- @ Override
1132- public boolean extensionEquals (ExtensionType other ) {
1133- return other instanceof UuidType ;
1134- }
1135-
1136- @ Override
1137- public ArrowType deserialize (ArrowType storageType , String serializedData ) {
1138- if (!storageType .equals (storageType ())) {
1139- throw new UnsupportedOperationException (
1140- "Cannot construct UuidType from underlying type " + storageType );
1141- }
1142- return new UuidType ();
1143- }
1144-
1145- @ Override
1146- public String serialize () {
1147- return "" ;
1148- }
1149-
1150- @ Override
1151- public FieldVector getNewVector (String name , FieldType fieldType , BufferAllocator allocator ) {
1152- return new UuidVector (name , allocator , new FixedSizeBinaryVector (name , allocator , 16 ));
1153- }
1154- }
1155-
1156- static class UuidVector extends ExtensionTypeVector <FixedSizeBinaryVector > {
1157-
1158- public UuidVector (
1159- String name , BufferAllocator allocator , FixedSizeBinaryVector underlyingVector ) {
1160- super (name , allocator , underlyingVector );
1161- }
1162-
1163- @ Override
1164- public UUID getObject (int index ) {
1165- final ByteBuffer bb = ByteBuffer .wrap (getUnderlyingVector ().getObject (index ));
1166- return new UUID (bb .getLong (), bb .getLong ());
1167- }
1168-
1169- @ Override
1170- public int hashCode (int index ) {
1171- return hashCode (index , null );
1172- }
1173-
1174- @ Override
1175- public int hashCode (int index , ArrowBufHasher hasher ) {
1176- return getUnderlyingVector ().hashCode (index , hasher );
1177- }
1178-
1179- public void set (int index , UUID uuid ) {
1180- ByteBuffer bb = ByteBuffer .allocate (16 );
1181- bb .putLong (uuid .getMostSignificantBits ());
1182- bb .putLong (uuid .getLeastSignificantBits ());
1183- getUnderlyingVector ().set (index , bb .array ());
1184- }
1185- }
11861115}
0 commit comments