Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.arrow.vectorized;

import org.apache.arrow.vector.NullCheckingForGet;
import org.apache.iceberg.formats.FormatModelRegistry;
import org.apache.iceberg.parquet.ParquetFormatModel;

public class ArrowFormatModels {
public static void register() {
FormatModelRegistry.register(
ParquetFormatModel.create(
ColumnarBatch.class,
Object.class,
(schema, fileSchema, engineSchema, idToConstant) ->
ArrowReader.VectorizedCombinedScanIterator.buildReader(
schema,
fileSchema,
NullCheckingForGet.NULL_CHECKING_ENABLED /* setArrowValidityVector */)));
}

private ArrowFormatModels() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.apache.arrow.vector.NullCheckingForGet;
import org.apache.arrow.vector.VectorSchemaRoot;
import org.apache.arrow.vector.types.Types.MinorType;
import org.apache.iceberg.CombinedScanTask;
Expand All @@ -40,13 +39,14 @@
import org.apache.iceberg.encryption.EncryptedFiles;
import org.apache.iceberg.encryption.EncryptedInputFile;
import org.apache.iceberg.encryption.EncryptionManager;
import org.apache.iceberg.formats.FormatModelRegistry;
import org.apache.iceberg.formats.ReadBuilder;
import org.apache.iceberg.io.CloseableGroup;
import org.apache.iceberg.io.CloseableIterable;
import org.apache.iceberg.io.CloseableIterator;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.io.InputFile;
import org.apache.iceberg.mapping.NameMappingParser;
import org.apache.iceberg.parquet.Parquet;
import org.apache.iceberg.parquet.TypeWithSchemaVisitor;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -189,8 +189,7 @@ public void close() throws IOException {
* Reads the data file and returns an iterator of {@link VectorSchemaRoot}. Only Parquet data file
* format is supported.
*/
private static final class VectorizedCombinedScanIterator
implements CloseableIterator<ColumnarBatch> {
static final class VectorizedCombinedScanIterator implements CloseableIterator<ColumnarBatch> {

private final Iterator<FileScanTask> fileItr;
private final Map<String, InputFile> inputFiles;
Expand Down Expand Up @@ -324,19 +323,8 @@ CloseableIterator<ColumnarBatch> open(FileScanTask task) {
InputFile location = getInputFile(task);
Preconditions.checkNotNull(location, "Could not find InputFile associated with FileScanTask");
if (task.file().format() == FileFormat.PARQUET) {
Parquet.ReadBuilder builder =
Parquet.read(location)
.project(expectedSchema)
.split(task.start(), task.length())
.createBatchedReaderFunc(
fileSchema ->
buildReader(
expectedSchema,
fileSchema, /* setArrowValidityVector */
NullCheckingForGet.NULL_CHECKING_ENABLED))
.recordsPerBatch(batchSize)
.filter(task.residual())
.caseSensitive(caseSensitive);
ReadBuilder<ColumnarBatch, ?> builder =
FormatModelRegistry.readBuilder(FileFormat.PARQUET, ColumnarBatch.class, location);

if (reuseContainers) {
builder.reuseContainers();
Expand All @@ -345,7 +333,14 @@ CloseableIterator<ColumnarBatch> open(FileScanTask task) {
builder.withNameMapping(NameMappingParser.fromJson(nameMapping));
}

iter = builder.build();
iter =
builder
.project(expectedSchema)
.split(task.start(), task.length())
.recordsPerBatch(batchSize)
.caseSensitive(caseSensitive)
.filter(task.residual())
.build();
} else {
throw new UnsupportedOperationException(
"Format: " + task.file().format() + " not supported for batched reads");
Expand Down Expand Up @@ -376,7 +371,7 @@ private InputFile getInputFile(FileScanTask task) {
* @param fileSchema Schema of the data file.
* @param setArrowValidityVector Indicates whether to set the validity vector in Arrow vectors.
*/
private static ArrowBatchReader buildReader(
static ArrowBatchReader buildReader(
Schema expectedSchema, MessageType fileSchema, boolean setArrowValidityVector) {
return (ArrowBatchReader)
TypeWithSchemaVisitor.visit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ private FormatModelRegistry() {}
private static final Logger LOG = LoggerFactory.getLogger(FormatModelRegistry.class);
// The list of classes which are used for registering the reader and writer builders
private static final List<String> CLASSES_TO_REGISTER =
ImmutableList.of("org.apache.iceberg.data.GenericFormatModels");
ImmutableList.of(
"org.apache.iceberg.data.GenericFormatModels",
"org.apache.iceberg.arrow.vectorized.ArrowFormatModels");

// Format models indexed by file format and object model class
private static final Map<Pair<FileFormat, Class<?>>, FormatModel<?, ?>> MODELS =
Expand Down