mcvsubbu commented on a change in pull request #4874: Pinot ingestion job - Standalone URL: https://github.com/apache/incubator-pinot/pull/4874#discussion_r353420452
########## File path: pinot-batch-ingestion/pinot-standalone/src/main/java/org/apache/pinot/ingestion/common/SegmentGenerationTaskRunner.java ########## @@ -0,0 +1,134 @@ +/** + * 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.ingestion.common; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Preconditions; +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import org.apache.pinot.common.config.SegmentsValidationAndRetentionConfig; +import org.apache.pinot.common.config.TableConfig; +import org.apache.pinot.core.indexsegment.generator.SegmentGeneratorConfig; +import org.apache.pinot.core.segment.creator.impl.SegmentIndexCreationDriverImpl; +import org.apache.pinot.core.segment.name.NormalizedDateSegmentNameGenerator; +import org.apache.pinot.core.segment.name.SegmentNameGenerator; +import org.apache.pinot.core.segment.name.SimpleSegmentNameGenerator; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.data.TimeFieldSpec; +import org.apache.pinot.spi.data.readers.RecordReader; +import org.apache.pinot.spi.data.readers.RecordReaderConfig; +import org.apache.pinot.spi.utils.JsonUtils; + + +public class SegmentGenerationTaskRunner { + + public static final String SIMPLE_SEGMENT_NAME_GENERATOR = "simple"; + public static final String NORMALIZED_DATE_SEGMENT_NAME_GENERATOR = "normalizedDate"; + + // For SimpleSegmentNameGenerator + public static final String SEGMENT_NAME_POSTFIX = "segment.name.postfix"; + + // For NormalizedDateSegmentNameGenerator + public static final String SEGMENT_NAME_PREFIX = "segment.name.prefix"; + public static final String EXCLUDE_SEQUENCE_ID = "exclude.sequence.id"; + + private SegmentGenerationTaskSpec _taskSpec; + + public SegmentGenerationTaskRunner(SegmentGenerationTaskSpec taskSpec) { + _taskSpec = taskSpec; + } + + public String run() + throws Exception { + String tableName = _taskSpec.getTableConfig().getTableName(); + TableConfig tableConfig = _taskSpec._tableConfig; + Schema schema = _taskSpec.getSchema(); + + //init record reader config + String readerConfigClassName = _taskSpec.getRecordReaderSpec().getConfigClassName(); + RecordReaderConfig recordReaderConfig = null; + + if (readerConfigClassName != null) { + Map<String, String> configs = _taskSpec.getRecordReaderSpec().getConfigs(); + if (configs == null) { + configs = new HashMap<>(); + } + JsonNode jsonNode = new ObjectMapper().valueToTree(configs); + JsonUtils.jsonNodeToObject(jsonNode, Class.forName(readerConfigClassName)); + recordReaderConfig = (RecordReaderConfig) Class.forName(readerConfigClassName).newInstance(); + } + + //init record reader + String readerClassName = _taskSpec.getRecordReaderSpec().getClassName(); + RecordReader recordReader = (RecordReader) Class.forName(readerClassName).newInstance(); + recordReader.init(new File(_taskSpec.getInputFilePath()), schema, recordReaderConfig); + + //init segmentName Generator + SegmentNameGenerator segmentNameGenerator = getSegmentNameGerator(); + + //init segment generation config + SegmentGeneratorConfig segmentGeneratorConfig = new SegmentGeneratorConfig(tableConfig, schema); + segmentGeneratorConfig.setTableName(tableName); + segmentGeneratorConfig.setOutDir(_taskSpec.getOutputDirectoryPath()); + segmentGeneratorConfig.setSegmentNameGenerator(segmentNameGenerator); + segmentGeneratorConfig.setSequenceId(_taskSpec.getSequenceId()); + + //build segment + SegmentIndexCreationDriverImpl segmentIndexCreationDriver = new SegmentIndexCreationDriverImpl(); + segmentIndexCreationDriver.init(segmentGeneratorConfig, recordReader); + segmentIndexCreationDriver.build(); + return segmentIndexCreationDriver.getSegmentName(); + } + + private SegmentNameGenerator getSegmentNameGerator() { + String tableName = _taskSpec.getTableConfig().getTableName(); + TableConfig tableConfig = _taskSpec._tableConfig; Review comment: ```suggestion TableConfig tableConfig = _taskSpec.getTableConfig(); ``` ---------------------------------------------------------------- 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]
