ViggoC commented on code in PR #43888:
URL: https://github.com/apache/arrow/pull/43888#discussion_r1765129961


##########
java/vector/src/main/java/org/apache/arrow/vector/complex/RunEndEncodedVector.java:
##########
@@ -0,0 +1,683 @@
+/*
+ * 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.complex;
+
+import static org.apache.arrow.util.Preconditions.checkArgument;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.OutOfMemoryException;
+import org.apache.arrow.memory.util.ByteFunctionHelpers;
+import org.apache.arrow.memory.util.hash.ArrowBufHasher;
+import org.apache.arrow.vector.BaseIntVector;
+import org.apache.arrow.vector.BaseValueVector;
+import org.apache.arrow.vector.BufferBacked;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.ValueVector;
+import org.apache.arrow.vector.ZeroVector;
+import org.apache.arrow.vector.compare.VectorVisitor;
+import org.apache.arrow.vector.complex.reader.FieldReader;
+import org.apache.arrow.vector.complex.writer.FieldWriter;
+import org.apache.arrow.vector.ipc.message.ArrowFieldNode;
+import org.apache.arrow.vector.types.Types.MinorType;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+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;
+
+/**
+ * A run-end encoded vector contains only two child vectors: a run_end vector 
of type int and a
+ * values vector of any type. There are no buffers associated with the parent 
vector.
+ */
+public class RunEndEncodedVector extends BaseValueVector implements 
FieldVector {
+  public static final FieldVector DEFAULT_VALUE_VECTOR = ZeroVector.INSTANCE;
+  public static final FieldVector DEFAULT_RUN_END_VECTOR = ZeroVector.INSTANCE;
+
+  public static RunEndEncodedVector empty(String name, BufferAllocator 
allocator) {
+    return new RunEndEncodedVector(
+        name, allocator, 
FieldType.notNullable(ArrowType.RunEndEncoded.INSTANCE), null);
+  }
+
+  protected final CallBack callBack;
+  protected Field field;
+  protected FieldVector runEndsVector;
+  protected FieldVector valuesVector;
+  protected int valueCount;
+
+  /**
+   * Constructs a new instance.
+   *
+   * @param name The name of the instance.
+   * @param allocator The allocator to use for allocating/reallocating buffers.
+   * @param fieldType The type of the array that is run-end encoded.
+   * @param callBack A schema change callback.
+   */
+  public RunEndEncodedVector(
+      String name, BufferAllocator allocator, FieldType fieldType, CallBack 
callBack) {
+    this(new Field(name, fieldType, null), allocator, callBack);
+  }
+
+  /**
+   * Constructs a new instance.
+   *
+   * @param field The field materialized by this vector.
+   * @param allocator The allocator to use for allocating/reallocating buffers.
+   * @param callBack A schema change callback.
+   */
+  public RunEndEncodedVector(Field field, BufferAllocator allocator, CallBack 
callBack) {
+    this(field, allocator, DEFAULT_RUN_END_VECTOR, DEFAULT_VALUE_VECTOR, 
callBack);
+  }
+
+  /**
+   * Constructs a new instance.
+   *
+   * @param field The field materialized by this vector.
+   * @param allocator The allocator to use for allocating/reallocating buffers.
+   * @param runEndsVector The vector represents run ends. Only Zero vector or 
type int vector with
+   *     size 16, 32 is allowed
+   * @param valuesVector The vector represents values
+   * @param callBack A schema change callback.
+   */
+  public RunEndEncodedVector(
+      Field field,
+      BufferAllocator allocator,
+      FieldVector runEndsVector,
+      FieldVector valuesVector,
+      CallBack callBack) {
+    super(allocator);
+    this.field = field;
+    this.callBack = callBack;
+    this.valueCount = 0;
+    this.runEndsVector = runEndsVector;
+    this.valuesVector = valuesVector;
+  }
+
+  /** ValueVector interface */
+
+  /**
+   * Allocate new buffers. ValueVector implements logic to determine how much 
to allocate.
+   *
+   * @throws OutOfMemoryException Thrown if no memory can be allocated.
+   */
+  @Override
+  public void allocateNew() throws OutOfMemoryException {
+    if (!allocateNewSafe()) {
+      throw new OutOfMemoryException("Failure while allocating memory");
+    }
+  }
+
+  /**
+   * Allocates new buffers. ValueVector implements logic to determine how much 
to allocate.
+   *
+   * @return Returns true if allocation was successful.
+   */
+  @Override
+  public boolean allocateNewSafe() {
+    initializeChildrenFromFields(field.getChildren());
+    for (FieldVector v : getChildrenFromFields()) {
+      boolean isAllocated = v.allocateNewSafe();
+      if (!isAllocated) {
+        v.clear();
+        return false;
+      }
+    }
+    return true;
+  }
+
+  /**
+   * Allocate new buffer with double capacity, and copy data into the new 
buffer. Replace vector's
+   * buffer with new buffer, and release old one
+   */
+  @Override
+  public void reAlloc() {
+    for (FieldVector v : getChildrenFromFields()) {
+      v.reAlloc();
+    }
+  }
+
+  @Override
+  public BufferAllocator getAllocator() {
+    return allocator;
+  }
+
+  @Override
+  protected FieldReader getReaderImpl() {
+    return null;

Review Comment:
   fixed in 
https://github.com/apache/arrow/pull/43888/commits/2b24d39257bbdbee8697532d766631ba570224dc



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