aokolnychyi commented on code in PR #9841:
URL: https://github.com/apache/iceberg/pull/9841#discussion_r1589703297


##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/SparkSQLProperties.java:
##########
@@ -27,6 +27,10 @@ private SparkSQLProperties() {}
   // Controls whether vectorized reads are enabled
   public static final String VECTORIZATION_ENABLED = 
"spark.sql.iceberg.vectorization.enabled";
 
+  // Controls which parquet reader to use for vectorization

Review Comment:
   Minor: `parquet` -> `Parquet` in the comment.



##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/SparkReadConf.java:
##########
@@ -353,4 +354,19 @@ private boolean executorCacheLocalityEnabledInternal() {
         
.defaultValue(SparkSQLProperties.EXECUTOR_CACHE_LOCALITY_ENABLED_DEFAULT)
         .parse();
   }
+
+  private ParquetReaderType parquetReaderType() {
+    return confParser
+        .enumConf(ParquetReaderType::valueOf)
+        .sessionConf(SparkSQLProperties.PARQUET_READER_TYPE)
+        .defaultValue(SparkSQLProperties.PARQUET_READER_TYPE_DEFAULT)
+        .parse();
+  }
+
+  public BatchReadConf batchReadConf() {
+    int parquetBatchSize = parquetBatchSize();
+    int orcBatchSize = orcBatchSize();
+    Preconditions.checkArgument(parquetBatchSize > 1 || orcBatchSize > 1, 
"Batch size must be > 1");

Review Comment:
   Why `||`?



##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/source/BaseBatchReader.java:
##########
@@ -32,23 +32,25 @@
 import org.apache.iceberg.orc.ORC;
 import org.apache.iceberg.parquet.Parquet;
 import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.apache.iceberg.spark.BatchReadConf;
+import org.apache.iceberg.spark.ParquetReaderType;
 import org.apache.iceberg.spark.data.vectorized.VectorizedSparkOrcReaders;
 import org.apache.iceberg.spark.data.vectorized.VectorizedSparkParquetReaders;
 import org.apache.iceberg.types.TypeUtil;
 import org.apache.spark.sql.vectorized.ColumnarBatch;
 
 abstract class BaseBatchReader<T extends ScanTask> extends 
BaseReader<ColumnarBatch, T> {
-  private final int batchSize;
+  private final BatchReadConf batchReadConf;

Review Comment:
   Optional: What about renaming `batchReadConf` to `conf` for shorter lines?



##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/data/vectorized/CometColumnReader.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.io.IOException;
+import java.util.Map;
+import org.apache.comet.parquet.AbstractColumnReader;
+import org.apache.comet.parquet.ColumnReader;
+import org.apache.comet.parquet.TypeUtil;
+import org.apache.comet.parquet.Utils;
+import org.apache.iceberg.parquet.VectorizedReader;
+import org.apache.iceberg.spark.SparkSchemaUtil;
+import org.apache.iceberg.types.Types;
+import org.apache.parquet.column.ColumnDescriptor;
+import org.apache.parquet.column.page.PageReadStore;
+import org.apache.parquet.column.page.PageReader;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnPath;
+import org.apache.spark.sql.internal.SQLConf;
+import org.apache.spark.sql.types.DataType;
+import org.apache.spark.sql.types.Metadata;
+import org.apache.spark.sql.types.StructField;
+
+/**
+ * A Iceberg Parquet column reader backed by a Comet {@link ColumnReader}. 
This class should be used
+ * together with {@link CometVector}.
+ *
+ * <p>Example:
+ *
+ * <pre>
+ *   CometColumnReader reader = ...
+ *   reader.setBatchSize(batchSize);
+ *
+ *   while (hasMoreRowsToRead) {
+ *     if (endOfRowGroup) {
+ *       reader.reset();
+ *       PageReader pageReader = ...
+ *       reader.setPageReader(pageReader);
+ *     }
+ *
+ *     int numRows = ...
+ *     CometVector vector = reader.read(null, numRows);
+ *
+ *     // consume the vector
+ *   }
+ *
+ *   reader.close();
+ * </pre>
+ */
+@SuppressWarnings({"checkstyle:VisibilityModifier", "ParameterAssignment"})
+class CometColumnReader implements VectorizedReader<CometVector> {
+  public static final int DEFAULT_BATCH_SIZE = 5000;
+
+  private final DataType sparkType;
+  protected AbstractColumnReader delegate;
+  private final CometVector vector;
+  private final ColumnDescriptor descriptor;
+  protected boolean initialized = false;
+  protected int batchSize = DEFAULT_BATCH_SIZE;
+
+  CometColumnReader(DataType sparkType, ColumnDescriptor descriptor) {
+    this.sparkType = sparkType;
+    this.descriptor = descriptor;
+    this.vector = new CometVector(sparkType, false);
+  }
+
+  CometColumnReader(Types.NestedField field) {
+    DataType dataType = SparkSchemaUtil.convert(field.type());
+    StructField structField = new StructField(field.name(), dataType, false, 
Metadata.empty());
+    this.sparkType = dataType;
+    this.descriptor = TypeUtil.convertToParquet(structField);
+    this.vector = new CometVector(sparkType, false);
+  }
+
+  public AbstractColumnReader getDelegate() {
+    return delegate;
+  }
+
+  /**
+   * This method is to initialized/reset the ColumnReader. This needs to be 
called for each row
+   * group after readNextRowGroup, so a new dictionary encoding can be set for 
each of the new row
+   * groups.
+   */
+  public void reset() {
+    if (delegate != null) {
+      delegate.close();
+    }
+
+    delegate = Utils.getColumnReader(sparkType, descriptor, batchSize, 
SQLConf.get());

Review Comment:
   Just out of my curiosity, why not call `SQLConf.get()` inside the method?



##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/BatchReadConf.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+
+public class BatchReadConf implements Serializable {
+
+  private int parquetBatchSize;

Review Comment:
   Let's make all three variables final. Also, can we group them based on the 
file format they belong to? Make sure to update the order of vars in the 
constructor and methods to match.
   
   



##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/source/SparkBatch.java:
##########
@@ -114,12 +114,9 @@ private String[][] computePreferredLocations() {
   @Override
   public PartitionReaderFactory createReaderFactory() {
     if (useParquetBatchReads()) {
-      int batchSize = readConf.parquetBatchSize();
-      return new SparkColumnarReaderFactory(batchSize);
-

Review Comment:
   We should preserve an empty line after the return statement.



##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/source/BatchDataReader.java:
##########
@@ -45,14 +46,14 @@ class BatchDataReader extends BaseBatchReader<FileScanTask>
 
   private final long numSplits;
 
-  BatchDataReader(SparkInputPartition partition, int batchSize) {
+  BatchDataReader(SparkInputPartition partition, BatchReadConf batchReadConf) {

Review Comment:
   Optional: `batchReadConf` -> `conf`?



##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/SparkReadConf.java:
##########
@@ -165,7 +166,7 @@ public boolean parquetVectorizationEnabled() {
         .parse();
   }
 
-  public int parquetBatchSize() {
+  private int parquetBatchSize() {

Review Comment:
   We probably shouldn't make these methods private for now. Our 
`SparkReadConf` is fairly public, so we should try avoid breaking it.



-- 
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: issues-unsubscr...@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to