kishoreg commented on a change in pull request #4888: Refactor file format based RecordReader constructors URL: https://github.com/apache/incubator-pinot/pull/4888#discussion_r354617461
########## File path: pinot-spi/src/main/java/org/apache/pinot/spi/data/readers/RecordReaderFactory.java ########## @@ -0,0 +1,203 @@ +/** + * 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.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.utils.JsonUtils; + + +public class RecordReaderFactory { + + private static final Map<String, String> DEFAULT_RECORD_READER_CLASS_MAP = new HashMap<>(); + private static final Map<String, String> DEFAULT_RECORD_READER_CONFIG_CLASS_MAP = new HashMap<>(); + + // TODO: This could be removed once we have dynamic loading plugins supports. + private static final String DEFAULT_AVRO_RECORD_READER_CLASS = "org.apache.pinot.avro.data.readers.AvroRecordReader"; + private static final String DEFAULT_CSV_RECORD_READER_CLASS = "org.apache.pinot.csv.data.readers.CSVRecordReader"; + private static final String DEFAULT_CSV_RECORD_READER_CONFIG_CLASS = + "org.apache.pinot.csv.data.readers.CSVRecordReaderConfig"; + private static final String DEFAULT_JSON_RECORD_READER_CLASS = "org.apache.pinot.json.data.readers.JSONRecordReader"; + private static final String DEFAULT_THRIFT_RECORD_READER_CLASS = + "org.apache.pinot.thrift.data.readers.ThriftRecordReader"; + private static final String DEFAULT_THRIFT_RECORD_READER_CONFIG_CLASS = + "org.apache.pinot.thrift.data.readers.ThriftRecordReaderConfig"; + private static final String DEFAULT_ORC_RECORD_READER_CLASS = "org.apache.pinot.orc.data.readers.ORCRecordReader"; + private static final String DEFAULT_PARQUET_RECORD_READER_CLASS = + "org.apache.pinot.parquet.data.readers.ParquetRecordReader"; + + private RecordReaderFactory() { + } + + public static void register(String fileFormat, String recordReaderClassName, String recordReaderConfigClassName) { + DEFAULT_RECORD_READER_CLASS_MAP.put(fileFormat.toUpperCase(), recordReaderClassName); + DEFAULT_RECORD_READER_CONFIG_CLASS_MAP.put(fileFormat.toUpperCase(), recordReaderConfigClassName); + } + + public static void register(FileFormat fileFormat, String recordReaderClassName, String recordReaderConfigClassName) { + register(fileFormat.name(), recordReaderClassName, recordReaderConfigClassName); + } + + /** + * Construct a RecordReaderConfig instance from a given file path. + * + * @param recordReaderConfigClassName + * @param readerConfigFile + * @return + * @throws IOException + * @throws ClassNotFoundException + */ + public static RecordReaderConfig getRecordReaderConfigByClassName(String recordReaderConfigClassName, String readerConfigFile) + throws IOException, ClassNotFoundException { + return getRecordReaderConfigByClassName(recordReaderConfigClassName, new File(readerConfigFile)); + } + + /** + * Construct a RecordReaderConfig instance from a given file. + * + * @param recordReaderConfigClassName + * @param readerConfigFile + * @return + * @throws IOException + * @throws ClassNotFoundException + */ + public static RecordReaderConfig getRecordReaderConfigByClassName(String recordReaderConfigClassName, File readerConfigFile) Review comment: do we need this method? Can we simplify RecordReaderConfig class-related methods. can we initialize the RecordReader with a simple properties/map object Another option is get rid of RecordReaderConfig completely and pass Map<String, Object> in RecordReader init method. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
