pvary commented on code in PR #17296:
URL: https://github.com/apache/iceberg/pull/17296#discussion_r3665150162


##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/VectorizedArrowReader.java:
##########
@@ -814,13 +816,49 @@ public void setBatchSize(int batchSize) {
         this.nulls = newNullabilityHolder(batchSize);
       }
 
+      // release the result vector when the batch grows, so the next read 
allocates a vector that
+      // fits the new batch size
+      if (vec != null && vec.getValueCapacity() < batchSize) {
+        vec.close();
+        this.vec = null;
+      }
+
+      this.resultBatchSize = (batchSize == 0) ? DEFAULT_BATCH_SIZE : batchSize;
       idReader.setBatchSize(batchSize);
       posReader.setBatchSize(batchSize);
     }
 
+    /**
+     * Returns the vector this batch is written into, which the reader owns 
and closes.
+     *
+     * <p>{@code reuse} is used the same way the parent reader uses it: a null 
holder means the
+     * caller does not want the previous vector reused, so it is released and 
reallocated, while a
+     * non-null holder keeps the current vector. Vectors are allocated for a 
full batch, so a batch
+     * always fits.
+     */
+    private BigIntVector resultVector(VectorHolder reuse) {
+      if (reuse == null || vec == null) {
+        if (vec != null) {
+          vec.close();
+        }
+
+        this.vec = allocateBigIntVector(ROW_ID_ARROW_FIELD, resultBatchSize);
+      } else {
+        vec.setValueCount(0);
+      }

Review Comment:
   nit:
   This is a bit easier to read
   ```suggestion
         if (reuse != null && vec != null) {
           vec.setValueCount(0);
         } else {
           if (vec != null) {
             vec.close();
           }
   
           this.vec = 
allocateBigIntVector(RowIdVectorReader.ROW_ID_ARROW_FIELD, resultBatchSize);
         }
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to