gszadovszky commented on code in PR #947:
URL: https://github.com/apache/arrow-java/pull/947#discussion_r2735652361


##########
vector/src/main/java/org/apache/arrow/vector/extension/VariantVector.java:
##########
@@ -0,0 +1,342 @@
+/*
+ * 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.extension;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.util.hash.ArrowBufHasher;
+import org.apache.arrow.vector.BitVectorHelper;
+import org.apache.arrow.vector.ExtensionTypeVector;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.ValueVector;
+import org.apache.arrow.vector.VarBinaryVector;
+import org.apache.arrow.vector.complex.AbstractStructVector;
+import org.apache.arrow.vector.complex.StructVector;
+import org.apache.arrow.vector.complex.reader.FieldReader;
+import org.apache.arrow.vector.holders.NullableVariantHolder;
+import org.apache.arrow.vector.holders.VariantHolder;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.arrow.vector.types.pojo.ArrowType.Binary;
+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.variant.Variant;
+
+public class VariantVector extends ExtensionTypeVector<StructVector> {

Review Comment:
   Referencing `VariantType` here would help the user understanding what this 
vector is for.



##########
flight/flight-sql-jdbc-driver/pom.xml:
##########
@@ -93,6 +93,11 @@ under the License.
                   
<exclude>com.google.errorprone:error_prone_annotations</exclude>
                   <exclude>com.google.code.findbugs:jsr305</exclude>
                   <exclude>com.google.j2objc:j2objc-annotations</exclude>
+                  <!-- Parquet transitive dependencies (from arrow-variant) 
that contain pre-shaded classes -->
+                  <exclude>org.apache.parquet:parquet-common</exclude>
+                  <exclude>org.apache.parquet:parquet-column</exclude>
+                  <exclude>org.apache.parquet:parquet-encoding</exclude>
+                  
<exclude>org.apache.parquet:parquet-format-structures</exclude>

Review Comment:
   This is not required if the variant is separated since flight does not 
depend on that module.



##########
arrow-variant/src/main/java/org/apache/arrow/vector/variant/Variant.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.variant;
+
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.UUID;
+import org.apache.arrow.memory.ArrowBuf;
+
+/**
+ * Wrapper around parquet-variant's Variant implementation.
+ *
+ * <p>This wrapper exists to isolate the parquet-variant dependency from 
Arrow's public API,
+ * allowing the vector module to expose variant functionality without 
requiring users to depend on
+ * parquet-variant directly. It also ensures that nested variant values (from 
arrays and objects)
+ * are consistently wrapped.
+ */
+public class Variant {
+
+  private final org.apache.parquet.variant.Variant delegate;
+
+  /** Creates a Variant from raw metadata and value byte arrays. */
+  public Variant(byte[] metadata, byte[] value) {
+    this.delegate = new org.apache.parquet.variant.Variant(value, metadata);
+  }
+
+  /** Creates a Variant by copying data from ArrowBuf instances. */
+  public Variant(
+      ArrowBuf metadataBuffer,
+      int metadataStart,
+      int metadataEnd,
+      ArrowBuf valueBuffer,
+      int valueStart,
+      int valueEnd) {
+    byte[] metadata = new byte[metadataEnd - metadataStart];
+    byte[] value = new byte[valueEnd - valueStart];
+    metadataBuffer.getBytes(metadataStart, metadata);
+    valueBuffer.getBytes(valueStart, value);
+    this.delegate = new org.apache.parquet.variant.Variant(value, metadata);
+  }
+
+  private Variant(org.apache.parquet.variant.Variant delegate) {
+    this.delegate = delegate;
+  }
+
+  public ByteBuffer getValueBuffer() {
+    return delegate.getValueBuffer();
+  }
+
+  public ByteBuffer getMetadataBuffer() {
+    return delegate.getMetadataBuffer();
+  }
+

Review Comment:
   I don't think we should expose these to the user.



##########
vector/src/main/java/module-info.java:
##########
@@ -46,6 +46,7 @@
   requires jdk.unsupported;
   requires org.apache.arrow.format;
   requires org.apache.arrow.memory.core;
+  requires org.apache.arrow.variant;

Review Comment:
   The `vector` module should not depend on `arrow-variant'



##########
vector/src/main/java/org/apache/arrow/vector/extension/VariantType.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.extension;
+
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.ValueVector;
+import org.apache.arrow.vector.complex.impl.VariantWriterImpl;
+import org.apache.arrow.vector.complex.writer.FieldWriter;
+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.FieldType;
+
+public final class VariantType extends ExtensionType {

Review Comment:
   Maybe adding some comments about the type referencing the related Parquet 
spec would help understanding this. It should also be mentioned that it is for 
the variant binary format and does not handle shredded data.



##########
vector/src/test/java/org/apache/arrow/vector/TestListVector.java:
##########


Review Comment:
   See above



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


Review Comment:
   Move these tests to `TestVariant`.



##########
vector/pom.xml:
##########
@@ -37,6 +37,17 @@ under the License.
       <groupId>org.apache.arrow</groupId>
       <artifactId>arrow-memory-core</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.arrow</groupId>
+      <artifactId>arrow-variant</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.arrow</groupId>
+      <artifactId>arrow-variant</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>

Review Comment:
   `vector` should not depend on `arrow-variant`



-- 
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]

Reply via email to