Jackie-Jiang commented on a change in pull request #5934: URL: https://github.com/apache/incubator-pinot/pull/5934#discussion_r480489910
########## File path: pinot-core/src/main/java/org/apache/pinot/core/segment/processing/collector/CollectorConfig.java ########## @@ -0,0 +1,85 @@ +/** + * 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.collector; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import java.util.Map; +import javax.annotation.Nullable; + + +/** + * Config for Collector + */ +@JsonDeserialize(builder = CollectorConfig.Builder.class) +public class CollectorConfig { + private static final CollectorFactory.CollectorType DEFAULT_COLLECTOR_TYPE = CollectorFactory.CollectorType.CONCAT; + + private final CollectorFactory.CollectorType _collectorType; + private final Map<String, ValueAggregatorFactory.ValueAggregatorType> _aggregatorTypeMap; + + private CollectorConfig(CollectorFactory.CollectorType collectorType, Review comment: It should also include sorted columns (list of columns, where records are sorted on the first column firstly, then second column etc.) ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/function/FunctionEvaluator.java ########## @@ -36,4 +36,9 @@ * Evaluate the function on the generic row and return the result */ Object evaluate(GenericRow genericRow); + + /** + * Evaluate the function on the given arguments + */ + Object evaluate(Object[] arguments); Review comment: The arguments should be a key-value pair instead of an array. How are you going to map the values to the function parameters? ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/function/InbuiltFunctionEvaluator.java ########## @@ -155,5 +177,10 @@ public String execute(GenericRow row) { public Object execute(GenericRow row) { return row.getValue(_column); } + + @Override + public Object execute(Object[] arguments) { + throw new UnsupportedOperationException("Operation not supported for ColumnExecutionNode"); Review comment: This API won't work for in-build functions because it needs to read column values in order to evaluate the function ########## File path: pinot-core/src/main/java/org/apache/pinot/core/segment/processing/framework/SegmentReducer.java ########## @@ -0,0 +1,151 @@ +/** + * 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.util.Iterator; +import org.apache.avro.file.DataFileWriter; +import org.apache.avro.generic.GenericData; +import org.apache.avro.generic.GenericDatumWriter; +import org.apache.pinot.core.segment.processing.collector.Collector; +import org.apache.pinot.core.segment.processing.collector.CollectorFactory; +import org.apache.pinot.core.segment.processing.utils.SegmentProcessorUtils; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.apache.pinot.spi.data.readers.RecordReader; +import org.apache.pinot.spi.data.readers.RecordReaderFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Reducer phase of the SegmentProcessorFramework + * Reads the avro files in the input directory and creates output avro files in the reducer output directory. + * The avro files in the input directory are expected to contain data for only 1 partition + * Performs operations on that partition data as follows: + * - concatenation/rollup of records + * - split + * - TODO: dedup + */ +public class SegmentReducer { + + private static final Logger LOGGER = LoggerFactory.getLogger(SegmentReducer.class); + private static final int MAX_RECORDS_TO_COLLECT = 5_000_000; + + private final File _reducerInputDir; + private final File _reducerOutputDir; + + private final String _reducerId; + private final Schema _pinotSchema; + private final org.apache.avro.Schema _avroSchema; + private final Collector _collector; + private final int _numRecordsPerPart; + + public SegmentReducer(String reducerId, File reducerInputDir, SegmentReducerConfig reducerConfig, + File reducerOutputDir) { + _reducerInputDir = reducerInputDir; + _reducerOutputDir = reducerOutputDir; + + _reducerId = reducerId; + _pinotSchema = reducerConfig.getPinotSchema(); + _avroSchema = SegmentProcessorUtils.convertPinotSchemaToAvroSchema(_pinotSchema); + _collector = CollectorFactory.getCollector(reducerConfig.getCollectorConfig(), _pinotSchema); + _numRecordsPerPart = reducerConfig.getNumRecordsPerPart(); + LOGGER.info("Initialized reducer with id: {}, input dir: {}, output dir: {}, collector: {}, numRecordsPerPart: {}", + _reducerId, _reducerInputDir, _reducerOutputDir, _collector.getClass(), _numRecordsPerPart); + } + + /** + * Reads the avro files in the input directory. + * Performs configured operations and outputs to other avro file(s) in the reducer output directory. + */ + public void reduce() + throws Exception { + + int part = 0; + for (File inputFile : _reducerInputDir.listFiles()) { + + RecordReader avroRecordReader = RecordReaderFactory + .getRecordReaderByClass("org.apache.pinot.plugin.inputformat.avro.AvroRecordReader", inputFile, + _pinotSchema.getColumnNames(), null); + + while (avroRecordReader.hasNext()) { + GenericRow next = avroRecordReader.next(); + + // Aggregations + _collector.collect(next); + + // Exceeded max records allowed to collect. Flush + if (_collector.size() == MAX_RECORDS_TO_COLLECT) { Review comment: Should we use `_numRecordsPerPart` here so that once the collector collects enough records, we flush them? ########## File path: pinot-core/src/main/java/org/apache/pinot/core/segment/processing/partitioner/PartitionFilter.java ########## @@ -0,0 +1,30 @@ +/** + * 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.partitioner; + +/** + * Used for filtering partitions in the mapper + */ +public interface PartitionFilter { Review comment: Why associating the filter with the partition? We can apply the filter to the records, then you can directly use the current `FunctionEvaluator` IMO, record filtering is easier to config and more intuitive. I cannot think of a use case where we have to apply the filter to the partition ########## File path: pinot-core/src/main/java/org/apache/pinot/core/segment/processing/partitioner/PartitionerFactory.java ########## @@ -0,0 +1,82 @@ +/** + * 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.partitioner; + +import com.google.common.base.Preconditions; + + +/** + * Factory for Partitioner and PartitionFilter + */ +public final class PartitionerFactory { + + private PartitionerFactory() { + + } + + public enum PartitionerType { + NO_OP, ROW_HASH, COLUMN_VALUE, TRANSFORM_FUNCTION, TABLE_PARTITION_CONFIG + } + + /** + * Construct a Partitioner using the PartitioningConfig + */ + public static Partitioner getPartitioner(PartitioningConfig config) { + + Partitioner partitioner = null; + switch (config.getPartitionerType()) { + case NO_OP: + partitioner = new NoOpPartitioner(); + break; + case ROW_HASH: Review comment: I feel ROW_HASH is not really useful. Maybe ROUND_ROBIN is enough? ---------------------------------------------------------------- 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