npawar commented on a change in pull request #5934: URL: https://github.com/apache/incubator-pinot/pull/5934#discussion_r479439110
########## File path: pinot-core/src/main/java/org/apache/pinot/core/segment/processing/framework/SegmentMapper.java ########## @@ -0,0 +1,148 @@ +/** + * 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.core.segment.processing.framework; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.apache.avro.Schema; +import org.apache.avro.file.DataFileWriter; +import org.apache.avro.generic.GenericData; +import org.apache.avro.generic.GenericDatumWriter; +import org.apache.pinot.core.data.readers.PinotSegmentRecordReader; +import org.apache.pinot.core.segment.processing.partitioner.PartitionFilter; +import org.apache.pinot.core.segment.processing.partitioner.Partitioner; +import org.apache.pinot.core.segment.processing.partitioner.PartitionerFactory; +import org.apache.pinot.core.segment.processing.transformer.RecordTransformer; +import org.apache.pinot.core.segment.processing.transformer.RecordTransformerFactory; +import org.apache.pinot.core.segment.processing.utils.SegmentProcessorUtils; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Mapper phase of the SegmentProcessorFramework. + * Reads the input segment and creates partitioned avro data files + * Performs: + * - record transformations + * - partitioning + * - partition filtering + */ +public class SegmentMapper { + + private static final Logger LOGGER = LoggerFactory.getLogger(SegmentMapper.class); + private final File _inputSegment; + private final File _mapperOutputDir; + + private final String _mapperId; + private final Schema _avroSchema; + private final RecordTransformer _recordTransformer; + private final Partitioner _partitioner; + private final PartitionFilter _partitionFilter; + private final Map<String, DataFileWriter<GenericData.Record>> _partitionToDataFileWriterMap = new HashMap<>(); + + public SegmentMapper(String mapperId, File inputSegment, SegmentMapperConfig mapperConfig, File mapperOutputDir) { + _inputSegment = inputSegment; + _mapperOutputDir = mapperOutputDir; + + _mapperId = mapperId; + _avroSchema = SegmentProcessorUtils.convertPinotSchemaToAvroSchema(mapperConfig.getPinotSchema()); + _recordTransformer = RecordTransformerFactory.getRecordTransformer(mapperConfig.getRecordTransformerConfig()); + _partitioner = PartitionerFactory.getPartitioner(mapperConfig.getPartitioningConfig()); + _partitionFilter = PartitionerFactory.getPartitionFilter(mapperConfig.getPartitioningConfig()); + LOGGER.info( + "Initialized mapper with id: {}, input segment: {}, output dir: {}, recordTransformer: {}, partitioner: {}, partitionFilter: {}", + _mapperId, _inputSegment, _mapperOutputDir, _recordTransformer.getClass(), _partitioner.getClass(), + _partitionFilter.getClass()); + } + + /** + * Reads the input segment and generates partitioned avro data files into the mapper output directory + * Records for each partition are put into a directory of its own withing the mapper output directory, identified by the partition name + */ + public void map() + throws Exception { + + PinotSegmentRecordReader segmentRecordReader = new PinotSegmentRecordReader(_inputSegment); + GenericRow reusableRow = new GenericRow(); + GenericData.Record reusableRecord = new GenericData.Record(_avroSchema); + + Set<String> selectedPartitions = new HashSet<>(); + Set<String> rejectedPartitions = new HashSet<>(); + + while (segmentRecordReader.hasNext()) { + reusableRow = segmentRecordReader.next(reusableRow); + + // Record transformation + reusableRow = _recordTransformer.transformRecord(reusableRow); Review comment: Currently no record filtering happens in transformRecord. If we want to do record filtering in Mapper, I think we can introduce a new phase, then it would become transform -> filter -> partition -> partitionFilter -> flush My goal in this phase was to mainly include everything that the current code (of segment merge/rollup) does, and also include everything that the realtime to offline project needs. Filtering wasn't required in either, so skipped it ---------------------------------------------------------------- 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