lidavidm commented on code in PR #903:
URL: https://github.com/apache/arrow-java/pull/903#discussion_r2508445643
##########
vector/src/main/java/org/apache/arrow/vector/FixedSizeExtensionType.java:
##########
Review Comment:
Is this really necessary?
##########
vector/src/main/java/org/apache/arrow/vector/complex/impl/UuidWriterImpl.java:
##########
@@ -30,18 +30,25 @@ public UuidWriterImpl(UuidVector vector) {
@Override
public void writeExtension(Object value) {
- UUID uuid = (UUID) value;
- ByteBuffer bb = ByteBuffer.allocate(16);
- bb.putLong(uuid.getMostSignificantBits());
- bb.putLong(uuid.getLeastSignificantBits());
- vector.setSafe(getPosition(), bb.array());
+ if (value instanceof byte[]) {
+ vector.setSafe(getPosition(), (byte[]) value);
+ } else if (value instanceof ArrowBuf) {
+ vector.setSafe(getPosition(), (ArrowBuf) value);
+ } else if (value instanceof java.util.UUID) {
+ vector.setSafe(getPosition(), (java.util.UUID) value);
+ } else {
+ throw new IllegalArgumentException("Unsupported value type for UUID: " +
value.getClass());
+ }
vector.setValueCount(getPosition() + 1);
}
@Override
public void write(ExtensionHolder holder) {
- UuidHolder uuidHolder = (UuidHolder) holder;
- vector.setSafe(getPosition(), uuidHolder.value);
+ if (holder instanceof UuidHolder) {
+ vector.setSafe(getPosition(), ((UuidHolder) holder).buffer);
+ } else if (holder instanceof NullableUuidHolder) {
+ vector.setSafe(getPosition(), ((NullableUuidHolder) holder).buffer);
+ }
vector.setValueCount(getPosition() + 1);
Review Comment:
Do we actually test all these cases?
##########
vector/src/main/java/org/apache/arrow/vector/UuidVector.java:
##########
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.vector;
+
+import static org.apache.arrow.vector.extension.UuidType.UUID_BYTE_WIDTH;
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.util.ArrowBufPointer;
+import org.apache.arrow.memory.util.hash.ArrowBufHasher;
+import org.apache.arrow.vector.complex.impl.UuidReaderImpl;
+import org.apache.arrow.vector.complex.reader.FieldReader;
+import org.apache.arrow.vector.extension.UuidType;
+import org.apache.arrow.vector.holders.NullableUuidHolder;
+import org.apache.arrow.vector.holders.UuidHolder;
+import org.apache.arrow.vector.types.pojo.Field;
+import org.apache.arrow.vector.types.pojo.FieldType;
+import org.apache.arrow.vector.util.CallBack;
+import org.apache.arrow.vector.util.TransferPair;
+import org.apache.arrow.vector.util.UuidUtility;
+
+/**
+ * Vector implementation for UUID values using {@link UuidType}.
+ *
+ * <p>Supports setting and retrieving UUIDs with efficient storage and
nullable value handling.
+ *
+ * <p>Usage:
+ *
+ * <pre>{@code
+ * UuidVector vector = new UuidVector("uuid_col", allocator);
+ * vector.set(0, UUID.randomUUID());
+ * UUID value = vector.getObject(0);
+ * }</pre>
+ *
+ * @see {@link UuidType}
+ * @see {@link UuidHolder}
+ * @see {@link NullableUuidHolder}
+ */
+public class UuidVector extends ExtensionTypeVector<FixedSizeBinaryVector>
+ implements ValueIterableVector<UUID>, FixedWidthVector,
FixedSizeExtensionType {
+ private final Field field;
+ public static final int TYPE_WIDTH = UUID_BYTE_WIDTH;
+
+ public UuidVector(
+ String name, BufferAllocator allocator, FixedSizeBinaryVector
underlyingVector) {
+ super(name, allocator, underlyingVector);
+ this.field = new Field(name, FieldType.nullable(new UuidType()), null);
+ }
+
+ public UuidVector(
+ String name,
+ FieldType fieldType,
+ BufferAllocator allocator,
+ FixedSizeBinaryVector underlyingVector) {
+ super(name, allocator, underlyingVector);
+ this.field = new Field(name, fieldType, null);
+ }
+
+ 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);
+ }
+
+ public UuidVector(Field field, BufferAllocator allocator) {
+ super(
+ field.getName(),
+ allocator,
+ new FixedSizeBinaryVector(field.getName(), allocator,
UUID_BYTE_WIDTH));
+ this.field = field;
+ }
+
+ @Override
+ public UUID getObject(int index) {
+ if (isSet(index) == 0) {
+ return null;
+ }
+ 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 int isSet(int index) {
+ return getUnderlyingVector().isSet(index);
+ }
+
+ public ArrowBuf get(int index) throws IllegalStateException {
+ if (NullCheckingForGet.NULL_CHECKING_ENABLED && this.isSet(index) == 0) {
+ throw new IllegalStateException("Value at index is null");
+ } else {
+ return getBufferSlicePostNullCheck(index);
+ }
+ }
+
+ public void get(int index, NullableUuidHolder holder) {
+ if (NullCheckingForGet.NULL_CHECKING_ENABLED && this.isSet(index) == 0) {
+ holder.isSet = 0;
+ } else {
+ holder.isSet = 1;
+ holder.buffer = getBufferSlicePostNullCheck(index);
+ }
+ }
+
+ public void get(int index, UuidHolder holder) {
+ if (NullCheckingForGet.NULL_CHECKING_ENABLED && this.isSet(index) == 0) {
+ holder.isSet = 0;
Review Comment:
Isn't the point of this holder that it can't be null?
##########
vector/src/main/java/org/apache/arrow/vector/UuidVector.java:
##########
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.vector;
+
+import static org.apache.arrow.vector.extension.UuidType.UUID_BYTE_WIDTH;
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.util.ArrowBufPointer;
+import org.apache.arrow.memory.util.hash.ArrowBufHasher;
+import org.apache.arrow.vector.complex.impl.UuidReaderImpl;
+import org.apache.arrow.vector.complex.reader.FieldReader;
+import org.apache.arrow.vector.extension.UuidType;
+import org.apache.arrow.vector.holders.NullableUuidHolder;
+import org.apache.arrow.vector.holders.UuidHolder;
+import org.apache.arrow.vector.types.pojo.Field;
+import org.apache.arrow.vector.types.pojo.FieldType;
+import org.apache.arrow.vector.util.CallBack;
+import org.apache.arrow.vector.util.TransferPair;
+import org.apache.arrow.vector.util.UuidUtility;
+
+/**
+ * Vector implementation for UUID values using {@link UuidType}.
+ *
+ * <p>Supports setting and retrieving UUIDs with efficient storage and
nullable value handling.
+ *
+ * <p>Usage:
+ *
+ * <pre>{@code
+ * UuidVector vector = new UuidVector("uuid_col", allocator);
+ * vector.set(0, UUID.randomUUID());
+ * UUID value = vector.getObject(0);
+ * }</pre>
+ *
+ * @see {@link UuidType}
Review Comment:
`@see` already generates a link.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]