vibhatha commented on code in PR #41285:
URL: https://github.com/apache/arrow/pull/41285#discussion_r1599594505


##########
java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueViewVector.java:
##########
@@ -0,0 +1,410 @@
+/*
+ * 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.memory.util.LargeMemoryUtil.capAtMaxInt;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.util.CommonUtil;
+import org.apache.arrow.util.Preconditions;
+import org.apache.arrow.vector.AddOrGetResult;
+import org.apache.arrow.vector.BaseFixedWidthVector;
+import org.apache.arrow.vector.BaseValueVector;
+import org.apache.arrow.vector.BaseVariableWidthVector;
+import org.apache.arrow.vector.DensityAwareVector;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.NullVector;
+import org.apache.arrow.vector.UInt4Vector;
+import org.apache.arrow.vector.ValueVector;
+import org.apache.arrow.vector.ZeroVector;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.arrow.vector.types.pojo.FieldType;
+import org.apache.arrow.vector.util.CallBack;
+import org.apache.arrow.vector.util.OversizedAllocationException;
+import org.apache.arrow.vector.util.SchemaChangeRuntimeException;
+
+public abstract class BaseRepeatedValueViewVector extends BaseValueVector
+    implements RepeatedValueVector, BaseListVector {
+
+  public static final FieldVector DEFAULT_DATA_VECTOR = ZeroVector.INSTANCE;
+  public static final String DATA_VECTOR_NAME = "$data$";
+
+  public static final byte OFFSET_WIDTH = 4;
+  public static final byte SIZE_WIDTH = 4;
+  protected ArrowBuf offsetBuffer;
+  protected ArrowBuf sizeBuffer;
+  protected FieldVector vector;
+  protected final CallBack repeatedCallBack;
+  protected int valueCount;
+  protected long offsetAllocationSizeInBytes = INITIAL_VALUE_ALLOCATION * 
OFFSET_WIDTH;
+  protected long sizeAllocationSizeInBytes = INITIAL_VALUE_ALLOCATION * 
SIZE_WIDTH;
+  private final String name;
+
+  protected String defaultDataVectorName = DATA_VECTOR_NAME;
+
+  protected BaseRepeatedValueViewVector(String name, BufferAllocator 
allocator, CallBack callBack) {
+    this(name, allocator, DEFAULT_DATA_VECTOR, callBack);
+  }
+
+  protected BaseRepeatedValueViewVector(
+      String name, BufferAllocator allocator, FieldVector vector, CallBack 
callBack) {
+    super(allocator);
+    this.name = name;
+    this.offsetBuffer = allocator.getEmpty();
+    this.sizeBuffer = allocator.getEmpty();
+    this.vector = Preconditions.checkNotNull(vector, "data vector cannot be 
null");
+    this.repeatedCallBack = callBack;
+    this.valueCount = 0;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+
+  @Override
+  public boolean allocateNewSafe() {
+    boolean dataAlloc = false;
+    try {
+      allocateBuffers();
+      dataAlloc = vector.allocateNewSafe();
+    } catch (Exception e) {
+      clear();
+      return false;
+    } finally {
+      if (!dataAlloc) {
+        clear();
+      }
+    }
+    return dataAlloc;
+  }

Review Comment:
   Yes, I get your point. It shouldn't be like that. Let me see if we can do 
that clear in the super class itself and avoid calling that in the child, but 
the issue could be the following. 
   
   The super class keeps the `sizeBuffer` and `offsetBuffer` while the child 
class keeps the `validityBuffer`. This is what is being done in the 
`ListVector` and I just used the same pattern. It makes the `clear` logic and 
rest of the `allocation` logic being done in two classes. 
   
   Do you have a preferred approach?



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