Skip to content

Commit f86d83d

Browse files
committed
remove ensureRegistered method from UuidType
1 parent c6d1eb2 commit f86d83d

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

vector/src/main/java/org/apache/arrow/vector/extension/UuidType.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.arrow.vector.extension;
1818

19-
import java.util.concurrent.atomic.AtomicBoolean;
2019
import org.apache.arrow.memory.BufferAllocator;
2120
import org.apache.arrow.vector.FieldVector;
2221
import org.apache.arrow.vector.FixedSizeBinaryVector;
@@ -64,21 +63,10 @@ public class UuidType extends ExtensionType {
6463
/** Storage type for UUID: FixedSizeBinary(16). */
6564
public static final ArrowType STORAGE_TYPE = new ArrowType.FixedSizeBinary(UUID_BYTE_WIDTH);
6665

67-
/** Registers the UuidType in the extension type registry. */
68-
private static final AtomicBoolean registered = new AtomicBoolean(false);
69-
7066
static {
7167
ExtensionTypeRegistry.register(INSTANCE);
7268
}
7369

74-
/** Register the extension type so it can be used globally. */
75-
public static void ensureRegistered() {
76-
if (!registered.getAndSet(true)) {
77-
// The values don't matter, we just need an instance
78-
ExtensionTypeRegistry.register(UuidType.INSTANCE);
79-
}
80-
}
81-
8270
@Override
8371
public ArrowType storageType() {
8472
return STORAGE_TYPE;

vector/src/test/java/org/apache/arrow/vector/TestUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.arrow.memory.BufferAllocator;
2121
import org.apache.arrow.vector.types.Types.MinorType;
2222
import org.apache.arrow.vector.types.pojo.ArrowType;
23+
import org.apache.arrow.vector.types.pojo.ExtensionTypeRegistry;
2324
import org.apache.arrow.vector.types.pojo.FieldType;
2425

2526
public class TestUtils {
@@ -62,4 +63,14 @@ public static String generateRandomString(int length) {
6263
}
6364
return sb.toString();
6465
}
66+
67+
/*
68+
* Ensure the extension type is registered, as there might other tests trying to unregister the
69+
* type. ex.: TestExtensionType#readUnderlyingType
70+
*/
71+
public static void ensureRegistered(ArrowType.ExtensionType type) {
72+
if (ExtensionTypeRegistry.lookup(type.extensionName()) == null) {
73+
ExtensionTypeRegistry.register(type);
74+
}
75+
}
6576
}

vector/src/test/java/org/apache/arrow/vector/TestUuidType.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.arrow.vector;
1818

19+
import static org.apache.arrow.vector.TestUtils.ensureRegistered;
1920
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2021
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2122
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -164,9 +165,9 @@ void testVectorOperations() {
164165

165166
@Test
166167
void testIpcRoundTrip() {
167-
UuidType.ensureRegistered();
168+
UuidType type = UuidType.INSTANCE;
169+
ensureRegistered(type);
168170

169-
UuidType type = new UuidType();
170171
Schema schema = new Schema(Collections.singletonList(Field.nullable("uuid", type)));
171172
byte[] serialized = schema.serializeAsMessage();
172173
Schema deserialized = Schema.deserializeMessage(ByteBuffer.wrap(serialized));
@@ -175,9 +176,9 @@ void testIpcRoundTrip() {
175176

176177
@Test
177178
void testVectorIpcRoundTrip() throws IOException {
178-
UuidType.ensureRegistered();
179+
UuidType type = UuidType.INSTANCE;
180+
ensureRegistered(type);
179181

180-
UuidType type = new UuidType();
181182
UUID uuid1 = UUID.randomUUID();
182183
UUID uuid2 = UUID.randomUUID();
183184

vector/src/test/java/org/apache/arrow/vector/types/pojo/TestExtensionType.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.arrow.vector.types.pojo;
1818

19+
import static org.apache.arrow.vector.TestUtils.ensureRegistered;
1920
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2021
import static org.junit.jupiter.api.Assertions.assertEquals;
2122
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -60,9 +61,9 @@ public class TestExtensionType {
6061
/** Test that a custom UUID type can be round-tripped through a temporary file. */
6162
@Test
6263
public void roundtripUuid() throws IOException {
63-
ExtensionTypeRegistry.register(new UuidType());
64+
ensureRegistered(UuidType.INSTANCE);
6465
final Schema schema =
65-
new Schema(Collections.singletonList(Field.nullable("a", new UuidType())));
66+
new Schema(Collections.singletonList(Field.nullable("a", UuidType.INSTANCE)));
6667
try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE);
6768
final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) {
6869
UUID u1 = UUID.randomUUID();
@@ -90,7 +91,7 @@ public void roundtripUuid() throws IOException {
9091
assertEquals(root.getSchema(), readerRoot.getSchema());
9192

9293
final Field field = readerRoot.getSchema().getFields().get(0);
93-
final UuidType expectedType = new UuidType();
94+
final UuidType expectedType = UuidType.INSTANCE;
9495
assertEquals(
9596
field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME),
9697
expectedType.extensionName());
@@ -114,9 +115,9 @@ public void roundtripUuid() throws IOException {
114115
/** Test that a custom UUID type can be read as its underlying type. */
115116
@Test
116117
public void readUnderlyingType() throws IOException {
117-
ExtensionTypeRegistry.register(new UuidType());
118+
ensureRegistered(UuidType.INSTANCE);
118119
final Schema schema =
119-
new Schema(Collections.singletonList(Field.nullable("a", new UuidType())));
120+
new Schema(Collections.singletonList(Field.nullable("a", UuidType.INSTANCE)));
120121
try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE);
121122
final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) {
122123
UUID u1 = UUID.randomUUID();
@@ -136,7 +137,7 @@ public void readUnderlyingType() throws IOException {
136137
writer.end();
137138
}
138139

139-
ExtensionTypeRegistry.unregister(new UuidType());
140+
ExtensionTypeRegistry.unregister(UuidType.INSTANCE);
140141

141142
try (final SeekableByteChannel channel =
142143
Files.newByteChannel(Paths.get(file.getAbsolutePath()));
@@ -154,7 +155,7 @@ public void readUnderlyingType() throws IOException {
154155
.getByteWidth());
155156

156157
final Field field = readerRoot.getSchema().getFields().get(0);
157-
final UuidType expectedType = new UuidType();
158+
final UuidType expectedType = UuidType.INSTANCE;
158159
assertEquals(
159160
field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME),
160161
expectedType.extensionName());
@@ -255,7 +256,7 @@ public void roundtripLocation() throws IOException {
255256

256257
@Test
257258
public void testVectorCompare() {
258-
UuidType uuidType = new UuidType();
259+
UuidType uuidType = UuidType.INSTANCE;
259260
ExtensionTypeRegistry.register(uuidType);
260261
try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE);
261262
UuidVector a1 =

0 commit comments

Comments
 (0)