You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/09/01 17:51:43 UTC

[GitHub] [incubator-pinot] npawar commented on a change in pull request #5934: Segment processing framework

npawar commented on a change in pull request #5934:
URL: https://github.com/apache/incubator-pinot/pull/5934#discussion_r481326091



##########
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:
       I have removed PartitionFilter step and introduced record filtering.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org