rdblue commented on a change in pull request #828: iceberg-spark changes for 
vectorized reads
URL: https://github.com/apache/incubator-iceberg/pull/828#discussion_r389116883
 
 

 ##########
 File path: 
spark/src/main/java/org/apache/iceberg/spark/data/vectorized/ColumnarBatchReaders.java
 ##########
 @@ -0,0 +1,96 @@
+/*
+ * 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.iceberg.spark.data.vectorized;
+
+import java.lang.reflect.Array;
+import java.util.List;
+import java.util.Map;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.iceberg.arrow.vectorized.VectorHolder;
+import org.apache.iceberg.arrow.vectorized.VectorizedArrowReader;
+import org.apache.iceberg.parquet.VectorizedReader;
+import org.apache.parquet.column.page.PageReadStore;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnPath;
+import org.apache.spark.sql.vectorized.ColumnVector;
+import org.apache.spark.sql.vectorized.ColumnarBatch;
+
+/**
+ * {@link VectorizedReader} that returns Spark's {@link ColumnarBatch} to 
support Spark's vectorized read path. The
+ * {@link ColumnarBatch} returned is created by passing in the Arrow vectors 
populated via delegated read calls to
+ * {@linkplain VectorizedArrowReader VectorReader(s)}.
+ */
+public class ColumnarBatchReaders implements VectorizedReader<ColumnarBatch> {
+  private final VectorizedArrowReader[] readers;
+  private final int batchSize;
+
+  public ColumnarBatchReaders(List<VectorizedReader> readers, int bSize) {
+    this.readers = (VectorizedArrowReader[]) Array.newInstance(
+        VectorizedArrowReader.class, readers.size());
+    int idx = 0;
+    for (VectorizedReader reader : readers) {
+      this.readers[idx] = (VectorizedArrowReader) reader;
+      idx++;
+    }
+    this.batchSize = bSize;
+  }
+
+  @Override
+  public final void setRowGroupInfo(PageReadStore pageStore, Map<ColumnPath, 
ColumnChunkMetaData> metaData) {
+    for (int i = 0; i < readers.length; i += 1) {
+      if (readers[i] != null) {
+        readers[i].setRowGroupInfo(pageStore, metaData);
+      }
+    }
+  }
+
+  @Override
+  public void reuseContainers(boolean reuse) {
+    for (VectorizedReader reader : readers) {
+      reader.reuseContainers(reuse);
+    }
+  }
+
+  @Override
+  public final ColumnarBatch read(int numValsToRead) {
+    ColumnVector[] arrowColumnVectors = new ColumnVector[readers.length];
+    int numRows = 0;
+    for (int i = 0; i < readers.length; i += 1) {
+      VectorHolder holder = readers[i].read(numValsToRead);
 
 Review comment:
   You might want to move this into a factory method for 
`IcebergArrowColumnVector` instead of embedding it here. This logic looks more 
related to how column vectors work than to the batch. Here, you could just call 
`IcebergArrowColumnVector.forHolder(holder)` and that would return either the 
null vector or a real one.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to