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


##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/ArrowBatchReader.java:
##########
@@ -43,16 +50,41 @@ public final ColumnarBatch read(ColumnarBatch reuse, int 
numRowsToRead) {
 
     ColumnVector[] columnVectors = new ColumnVector[readers.length];
     for (int i = 0; i < readers.length; i += 1) {
-      vectorHolders[i] = readers[i].read(vectorHolders[i], numRowsToRead);
-      int numRowsInVector = vectorHolders[i].numValues();
+      VectorHolder holder = readers[i].read(vectorHolders[i], numRowsToRead);
+      if (holder.isDummy()) {
+        // The column is not in the data file, so the reader returns the value 
it should be read as
+        // instead of a vector. Build a vector holding that value because 
callers read a batch as an
+        // Arrow VectorSchemaRoot, which has no way to represent a column 
without a vector.
+        closeVector(vectorHolders[i]);
+        holder = constantHolder(fields.get(i), holder, numRowsToRead);
+      }
+
+      vectorHolders[i] = holder;
+      int numRowsInVector = holder.numValues();
       Preconditions.checkState(
           numRowsInVector == numRowsToRead,
           "Number of rows in the vector %s didn't match expected %s ",
           numRowsInVector,
           numRowsToRead);
-      // Handle null vector for constant case
-      columnVectors[i] = new ColumnVector(vectorHolders[i]);
+      columnVectors[i] = new ColumnVector(holder);
     }
     return new ColumnarBatch(numRowsToRead, columnVectors);
   }
+
+  private VectorHolder constantHolder(
+      Types.NestedField field, VectorHolder dummyHolder, int numRows) {
+    Object constant =
+        dummyHolder instanceof ConstantVectorHolder
+            ? ((ConstantVectorHolder<?>) dummyHolder).getConstant()
+            : null;

Review Comment:
   We can get the field from the `(ConstantVectorHolder)dummyHolder`. That 
would simplify things a bit



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