jenniferdai commented on a change in pull request #4253: Add segment pre-processing Hadoop job URL: https://github.com/apache/incubator-pinot/pull/4253#discussion_r290848855
########## File path: pinot-hadoop/src/main/java/org/apache/pinot/hadoop/job/SegmentPreprocessingJob.java ########## @@ -0,0 +1,479 @@ +/** + * 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.hadoop.job; + +import com.google.common.base.Preconditions; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.zip.GZIPInputStream; +import javax.annotation.Nullable; +import org.apache.avro.Schema; +import org.apache.avro.file.DataFileStream; +import org.apache.avro.generic.GenericDatumReader; +import org.apache.avro.generic.GenericRecord; +import org.apache.avro.mapred.AvroKey; +import org.apache.avro.mapred.AvroValue; +import org.apache.avro.mapreduce.AvroJob; +import org.apache.avro.mapreduce.AvroKeyOutputFormat; +import org.apache.avro.mapreduce.AvroMultipleOutputs; +import org.apache.commons.lang3.StringUtils; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.conf.Configured; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.FsPermission; +import org.apache.hadoop.io.NullWritable; +import org.apache.hadoop.mapred.JobContext; +import org.apache.hadoop.mapreduce.Job; +import org.apache.hadoop.mapreduce.MRJobConfig; +import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; +import org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter; +import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; +import org.apache.hadoop.mapreduce.lib.output.LazyOutputFormat; +import org.apache.pinot.common.Utils; +import org.apache.pinot.common.config.ColumnPartitionConfig; +import org.apache.pinot.common.config.IndexingConfig; +import org.apache.pinot.common.config.SegmentPartitionConfig; +import org.apache.pinot.common.config.TableConfig; +import org.apache.pinot.hadoop.io.CombineAvroKeyInputFormat; +import org.apache.pinot.hadoop.job.mapper.SegmentPreprocessingMapper; +import org.apache.pinot.hadoop.job.partitioners.GenericPartitioner; +import org.apache.pinot.hadoop.job.reducer.SegmentPreprocessingReducer; +import org.apache.pinot.hadoop.utils.JobPreparationHelper; +import org.apache.pinot.hadoop.utils.PushLocation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.pinot.hadoop.job.JobConfigConstants.*; + + +public class SegmentPreprocessingJob extends Configured { + private static final Logger _logger = LoggerFactory.getLogger(SegmentPreprocessingJob.class); + private final Properties _properties; + private Configuration _configuration; + + private boolean _enablePartitioning = false; + private boolean _enableSorting = false; + private boolean _enableResizing = false; + + private String _partitionColumn; + private int _numberOfPartitions; + private String _partitionFunction; + private String _sortedColumn; + private int _numberOfOutputFiles; + + private final String _inputSegmentDir; + private final String _preprocessedOutputDir; + protected final String _rawTableName; + + private final String _pathToDependencyJar; + private final String _defaultPermissionsMask; + protected final List<PushLocation> _pushLocations; + + private TableConfig _tableConfig; + protected FileSystem _fileSystem; + + public SegmentPreprocessingJob(final Properties properties) { + _properties = properties; + _configuration = new Configuration(); + setConf(_configuration); + Utils.logVersions(); + logProperties(); + + if (_properties.getProperty(ENABLE_PARTITIONING) != null) { + _enablePartitioning = Boolean.parseBoolean(_properties.getProperty(ENABLE_PARTITIONING)); + } + + if (_properties.getProperty(ENABLE_SORTING) != null) { + _enableSorting = Boolean.parseBoolean(_properties.getProperty(ENABLE_SORTING)); + } + + if (!_enablePartitioning && _properties.getProperty(ENABLE_RESIZING) != null) { + _enableResizing = Boolean.parseBoolean(_properties.getProperty(ENABLE_RESIZING)); + } + + // get input/output paths. + _inputSegmentDir = properties.getProperty(PATH_TO_INPUT); + _preprocessedOutputDir = properties.getProperty(PATH_TO_OUTPUT); + _rawTableName = Preconditions.checkNotNull(_properties.getProperty(JobConfigConstants.SEGMENT_TABLE_NAME)); + + _pathToDependencyJar = _properties.getProperty(PATH_TO_DEPS_JAR, null); + _defaultPermissionsMask = _properties.getProperty(JobConfigConstants.DEFAULT_PERMISSIONS_MASK, null); + + // Optional push location and table parameters. If set, will use the table config and schema from the push hosts. + String pushHostsString = _properties.getProperty(JobConfigConstants.PUSH_TO_HOSTS); + String pushPortString = _properties.getProperty(JobConfigConstants.PUSH_TO_PORT); + if (pushHostsString != null && pushPortString != null) { + _pushLocations = + PushLocation.getPushLocations(StringUtils.split(pushHostsString, ','), Integer.parseInt(pushPortString)); + } else { + _pushLocations = null; + } + + _logger.info("*********************************************************************"); + _logger.info("enable.partitioning: {}", _enablePartitioning); + _logger.info("enable.sorting: {}", _enableSorting); + _logger.info("enable.resizing: {}", _enableResizing); + _logger.info("path.to.input: {}", _inputSegmentDir); + _logger.info("path.to.output: {}", _preprocessedOutputDir); + _logger.info("path.to.deps.jar: {}", _pathToDependencyJar); + _logger.info("push.locations: {}", _pushLocations); + _logger.info("*********************************************************************"); + } + + public void run() throws Exception { + if (!_enablePartitioning && !_enableSorting && !_enableResizing) { + _logger.info("Pre-computing job is disabled."); + return; + } else { + _logger.info("Starting {}", getClass().getSimpleName()); + } + + _fileSystem = FileSystem.get(_configuration); + final List<String> inputDataPath = Arrays.asList(_inputSegmentDir.split("\\s*,\\s*")); + Path outputDir = new Path(_preprocessedOutputDir); + + if (_fileSystem.exists(outputDir)) { Review comment: want to confirm, which output dir is this? is this the same output dir as the pbnj segment creation step? (assuming we set the segment creation step properly?) or is it just one level in? perhaps we can use a different default path to output, not sure what our default is - in segment creation, we actually don't require one, we have a default, so we should have a default here too, perhaps /preprocess? ---------------------------------------------------------------- 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]
