liyafan82 commented on a change in pull request #7290:
URL: https://github.com/apache/arrow/pull/7290#discussion_r439335068



##########
File path: java/vector/src/main/codegen/templates/UnionVector.java
##########
@@ -325,12 +361,45 @@ private void allocateTypeBuffer() {
     typeBuffer.setZero(0, typeBuffer.capacity());
   }
 
+  private void allocateValidityBuffer() {
+    validityBuffer = allocator.buffer(validityBufferAllocationSizeInBytes);
+    validityBuffer.readerIndex(0);
+    validityBuffer.setZero(0, validityBuffer.capacity());
+  }
+
   @Override
   public void reAlloc() {
     internalStruct.reAlloc();
+    reallocValidityBuffer();
     reallocTypeBuffer();
   }
 
+  private void reallocValidityBuffer() {
+    final long currentBufferCapacity = validityBuffer.capacity();
+    long newAllocationSize = currentBufferCapacity * 2;
+    if (newAllocationSize == 0) {
+      if (validityBufferAllocationSizeInBytes > 0) {
+        newAllocationSize = validityBufferAllocationSizeInBytes;
+      } else {
+        newAllocationSize = 
DataSizeRoundingUtil.divideBy8Ceil(BaseValueVector.INITIAL_VALUE_ALLOCATION) * 
2;
+      }
+    }
+
+    newAllocationSize = CommonUtil.nextPowerOfTwo(newAllocationSize);
+    assert newAllocationSize >= 1;
+
+    if (newAllocationSize > BaseValueVector.MAX_ALLOCATION_SIZE) {
+      throw new OversizedAllocationException("Unable to expand the buffer");
+    }
+
+    final ArrowBuf newBuf = allocator.buffer((int)newAllocationSize);
+    newBuf.setBytes(0, validityBuffer, 0, currentBufferCapacity);
+    newBuf.setZero(currentBufferCapacity, newBuf.capacity() - 
currentBufferCapacity);
+    validityBuffer.getReferenceManager().release(1);
+    validityBuffer = newBuf;
+    validityBufferAllocationSizeInBytes = (int)newAllocationSize;

Review comment:
       there should be a space after the cast, or the style check would fail?




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to