siddharthteotia commented on code in PR #18638: URL: https://github.com/apache/pinot/pull/18638#discussion_r3384721852
########## pinot-plugins/pinot-input-format/pinot-arrow/src/main/java/org/apache/pinot/plugin/inputformat/arrow/ArrowAccumulators.java: ########## @@ -0,0 +1,184 @@ +/** + * 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.pinot.plugin.inputformat.arrow; + +import com.google.common.base.Preconditions; +import java.io.IOException; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; +import org.apache.arrow.memory.BufferAllocator; +import org.apache.arrow.vector.FieldVector; +import org.apache.arrow.vector.VectorSchemaRoot; +import org.apache.arrow.vector.ipc.ArrowReader; +import org.apache.arrow.vector.util.VectorAppender; +import org.apache.pinot.spi.data.FieldSpec; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.data.readers.ColumnReader; + + +/** + * Package-private helper shared by {@link ArrowColumnReaderFactory} and + * {@link InMemoryArrowColumnReaderFactory}: walks every record batch in an {@link ArrowReader}, + * concatenates each wanted column's values into a per-column accumulator {@link FieldVector} via + * Arrow's {@link VectorAppender}, and produces one {@link ArrowColumnReader} per accumulator. + * + * <p>Accumulator vectors are allocated against the caller-supplied {@link BufferAllocator}. The + * caller (factory) owns and closes them via {@link Result#getAccumulators()}; this helper does + * not retain references. + */ +final class ArrowAccumulators { + + private ArrowAccumulators() { + } + + static Result populate(ArrowReader reader, BufferAllocator allocator, Schema targetSchema, + @Nullable Set<String> colsToRead) + throws IOException { + Set<String> wantedColumns = computeWantedColumns(targetSchema, colsToRead); + + VectorSchemaRoot perBatchRoot = reader.getVectorSchemaRoot(); + Set<String> availableColumns = Collections.unmodifiableSet(collectAvailableNames(perBatchRoot)); + + Map<String, FieldVector> accumulators = new LinkedHashMap<>(); + Map<String, VectorAppender> appenders = new LinkedHashMap<>(); + for (FieldVector source : perBatchRoot.getFieldVectors()) { + String name = source.getField().getName(); + if (!wantedColumns.isEmpty() && !wantedColumns.contains(name)) { + continue; + } + // Dictionary-encoded columns surface as their index type (e.g. Int32) rather than the + // decoded logical type. Reject loudly so we don't silently produce a wrong segment. The + // row-major ArrowRecordExtractor decodes via DictionaryEncoder.decode; adding the same + // here is left as a follow-up once a real use case appears. + Preconditions.checkArgument(source.getField().getDictionary() == null, + "Dictionary-encoded Arrow column '%s' is not supported by Arrow column-major build. " + + "Use ArrowRecordReader (row-major) for files containing dictionary-encoded columns.", Review Comment: I am curious why are we rejecting dictionary encoded columns. It is the standard representation in Arrow (esp for low cardinality strings) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
