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_r410522943
########## File path: spark/src/main/java/org/apache/iceberg/spark/data/vectorized/VectorizedSparkParquetReaders.java ########## @@ -0,0 +1,146 @@ +/* + * 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 com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import org.apache.arrow.memory.BufferAllocator; +import org.apache.iceberg.Schema; +import org.apache.iceberg.arrow.vectorized.VectorizedArrowReader; +import org.apache.iceberg.parquet.TypeWithSchemaVisitor; +import org.apache.iceberg.parquet.VectorizedReader; +import org.apache.iceberg.spark.arrow.ArrowAllocation; +import org.apache.iceberg.types.Types; +import org.apache.parquet.column.ColumnDescriptor; +import org.apache.parquet.schema.GroupType; +import org.apache.parquet.schema.MessageType; +import org.apache.parquet.schema.PrimitiveType; +import org.apache.parquet.schema.Type; + +public class VectorizedSparkParquetReaders { + + private VectorizedSparkParquetReaders() { + } + + @SuppressWarnings("unchecked") + public static ColumnarBatchReaders buildReader( + Schema tableSchema, + Schema expectedSchema, + MessageType fileSchema, + Integer recordsPerBatch) { + return (ColumnarBatchReaders) + TypeWithSchemaVisitor.visit(expectedSchema.asStruct(), fileSchema, + new VectorizedReaderBuilder(tableSchema, expectedSchema, fileSchema, recordsPerBatch)); + } + + private static class VectorizedReaderBuilder extends TypeWithSchemaVisitor<VectorizedReader> { + private final MessageType parquetSchema; + private final Schema tableIcebergSchema; + private final BufferAllocator rootAllocator; + private final int batchSize; + + VectorizedReaderBuilder( + Schema tableSchema, + Schema projectedIcebergSchema, Review comment: This doesn't use `projectedIcebergSchema`. Can you remove it? Also, I think it would be possible to use just the expected schema instead of the table schema. In `primitive`, the table schema is used to find the Iceberg type. But if the Iceberg type is missing from the projection, then it can't be projected and will be skipped later. So it should be safe to do this: ```java ... ColumnDescriptor desc = parquetSchema.getColumnDescription(currentPath()); // Nested types not yet supported for vectorized reads if (desc.getMaxRepetitionLevel() > 0) { return null; } Types.NestedField icebergField = icebergSchema.findField(parquetFieldId); if (icebergField == null) { return null; } return new VectorizedArrowReader( desc, icebergField, rootAllocator, batchSize, false /* setArrowValidityVector */); ``` If that works, then you wouldn't need to pass the file schema all the way in. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org