fx19880617 commented on a change in pull request #6525: URL: https://github.com/apache/incubator-pinot/pull/6525#discussion_r578135413
########## File path: pinot-plugins/pinot-input-format/pinot-parquet/src/main/java/org/apache/pinot/plugin/inputformat/parquet/ParquetNativeRecordExtractor.java ########## @@ -0,0 +1,257 @@ +/** + * 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.parquet; + +import com.google.common.collect.ImmutableSet; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; +import org.apache.parquet.example.data.Group; +import org.apache.parquet.io.api.Binary; +import org.apache.parquet.schema.DecimalMetadata; +import org.apache.parquet.schema.OriginalType; +import org.apache.parquet.schema.Type; +import org.apache.pinot.spi.data.readers.BaseRecordExtractor; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.apache.pinot.spi.data.readers.RecordExtractorConfig; +import org.joda.time.DateTimeConstants; + +import static java.lang.Math.pow; + + +public class ParquetNativeRecordExtractor extends BaseRecordExtractor<Group> { + + /** + * Number of days between Julian day epoch (January 1, 4713 BC) and Unix day epoch (January 1, 1970). + * The value of this constant is {@value}. + */ + public static final long JULIAN_DAY_NUMBER_FOR_UNIX_EPOCH = 2440588; + + public static final long NANOS_PER_MILLISECOND = 1000000; + + private Set<String> _fields; + private boolean _extractAll = false; + + @Override + public void init(@Nullable Set<String> fields, RecordExtractorConfig recordExtractorConfig) { + if (fields == null || fields.isEmpty()) { + _extractAll = true; + _fields = Collections.emptySet(); + } else { + _fields = ImmutableSet.copyOf(fields); + } + } + + @Override + public GenericRow extract(Group from, GenericRow to) { + if (_extractAll) { + List<Type> fields = from.getType().getFields(); + for (Type field : fields) { + String fieldName = field.getName(); + Object value = extractValue(from, from.getType().getFieldIndex(fieldName)); + if (value != null) { + value = convert(value); + } + to.putValue(fieldName, value); + } + } else { + for (String fieldName : _fields) { + Object value = extractValue(from, from.getType().getFieldIndex(fieldName)); + if (value != null) { + value = convert(value); + } + to.putValue(fieldName, value); + } + } + return to; + } + + private Object extractValue(Group from, int fieldIndex) { + int valueCount = from.getFieldRepetitionCount(fieldIndex); + Type fieldType = from.getType().getType(fieldIndex); + if (valueCount == 0) { + return null; + } + if (valueCount == 1) { + return extractValue(from, fieldIndex, fieldType, 0); + } + Object[] results = new Object[valueCount]; + for (int index = 0; index < valueCount; index++) { Review comment: done. ---------------------------------------------------------------- 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 --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org