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_r410527253
########## File path: spark/src/main/java/org/apache/iceberg/spark/source/BatchDataReader.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.source; + +import com.google.common.base.Preconditions; +import java.util.Iterator; +import org.apache.iceberg.CombinedScanTask; +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.FileScanTask; +import org.apache.iceberg.Schema; +import org.apache.iceberg.encryption.EncryptionManager; +import org.apache.iceberg.io.CloseableIterable; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.parquet.Parquet; +import org.apache.iceberg.spark.SparkSchemaUtil; +import org.apache.iceberg.spark.data.vectorized.VectorizedSparkParquetReaders; +import org.apache.spark.sql.types.StructType; +import org.apache.spark.sql.vectorized.ColumnarBatch; + +class BatchDataReader extends BaseDataReader<ColumnarBatch> { + private final Schema tableSchema; + private final Schema expectedSchema; + private final boolean caseSensitive; + private final int batchSize; + + BatchDataReader( + CombinedScanTask task, Schema tableSchema, Schema expectedSchema, FileIO fileIo, + EncryptionManager encryptionManager, boolean caseSensitive, int size) { + super(task, fileIo, encryptionManager); + this.tableSchema = tableSchema; + this.expectedSchema = expectedSchema; + this.caseSensitive = caseSensitive; + this.batchSize = size; + } + + @Override + Iterator<ColumnarBatch> open(FileScanTask task) { + // schema or rows returned by readers + Schema finalSchema = expectedSchema; + // schema needed for the projection and filtering + StructType sparkType = SparkSchemaUtil.convert(finalSchema); + Schema requiredSchema = SparkSchemaUtil.prune(tableSchema, sparkType, task.residual(), caseSensitive); + boolean hasExtraFilterColumns = requiredSchema.columns().size() != finalSchema.columns().size(); + Iterator<ColumnarBatch> iter; + if (hasExtraFilterColumns) { Review comment: We need to make sure the extra filter columns are added in the reader and returned to Spark (so Spark expects the projection). This can't return a different set of columns than expected because columns are accessed by ordinal. Another option is to do the `ColumnarBatch` projection here (remove filter columns that have been used), but I would prefer to just return everything to Spark. That simplifies both row and batch read paths. ---------------------------------------------------------------- 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]
