timsants commented on a change in pull request #6046: URL: https://github.com/apache/incubator-pinot/pull/6046#discussion_r495613455
########## File path: pinot-spi/src/main/java/org/apache/pinot/spi/data/readers/AbstractDefaultRecordExtractor.java ########## @@ -0,0 +1,166 @@ +/** + * 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.spi.data.readers; + +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; + + +/** + * Abstract class for extracting and converting the fields of various data formats into supported Pinot data types. + * + * @param <T> the format of the input record + * @param <V> value used for converting the nested/complex fields of the file format (e.g. GenericRecord for Avro). + * In most cases, this will be the same type as {@code T}. + */ +public abstract class AbstractDefaultRecordExtractor<T, V> implements RecordExtractor<T, Object> { + + /** + * Converts the field value to either a single value (string, number, bytebuffer), multi value (Object[]) or a Map. + * Returns {@code null} if the field value is {@code null}. + * + * Natively Pinot only understands single values and multi values. + * Map is useful only if some ingestion transform functions operates on it in the transformation layer. + */ + @Nullable + public Object convert(@Nullable Object value) { + if (value == null) { + return null; + } + Object convertedValue; + if (isInstanceOfMultiValue(value)) { + convertedValue = convertMultiValue(value); + } else if (isInstanceOfMap(value)) { + convertedValue = convertMap(value); + } else if (isInstanceOfRecord(value)) { + convertedValue = convertRecord((V) value); + } else { + convertedValue = convertSingleValue(value); + } + return convertedValue; + } + + /** + * Returns whether the object is an instance of the data format's base type. + */ + protected abstract boolean isInstanceOfRecord(Object value); Review comment: Sounds good. This would help simplify the JSON extractor. ---------------------------------------------------------------- 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