siddharthteotia commented on code in PR #10636: URL: https://github.com/apache/pinot/pull/10636#discussion_r1188230046
########## pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/ChildAggregationFunction.java: ########## @@ -0,0 +1,160 @@ +/** + * 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.query.aggregation.function; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.apache.pinot.common.request.context.ExpressionContext; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.core.common.BlockValSet; +import org.apache.pinot.core.query.aggregation.AggregationResultHolder; +import org.apache.pinot.core.query.aggregation.groupby.DummyAggregationResultHolder; +import org.apache.pinot.core.query.aggregation.groupby.DummyGroupByResultHolder; +import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder; +import org.apache.pinot.spi.utils.CommonConstants; + + +/** + * Child aggregation function is used for a result placeholder during the query processing, + * It holds the position of the original aggregation function in the query + * and use its name to denote which parent aggregation function it belongs to. + * The name also serves as the key to retrieve the result from the parent aggregation function + * result holder. + * Please look at getResultColumnName() for the detailed format of the name. + * Please look at ArgMinMaxRewriter as an example of how a child aggregation function is created. + */ +public abstract class ChildAggregationFunction implements AggregationFunction<Long, Long> { + + private static final int CHILD_AGGREGATION_FUNCTION_ID_OFFSET = 0; + private static final int CHILD_AGGREGATION_FUNCTION_COLUMN_KEY_OFFSET = 1; + private final ExpressionContext _childFunctionKeyInParent; + private final List<ExpressionContext> _resultNameOperands; + private final ExpressionContext _childFunctionID; + + ChildAggregationFunction(List<ExpressionContext> operands) { + _childFunctionID = operands.get(CHILD_AGGREGATION_FUNCTION_ID_OFFSET); + _childFunctionKeyInParent = operands.get(CHILD_AGGREGATION_FUNCTION_COLUMN_KEY_OFFSET); + _resultNameOperands = operands.subList(CHILD_AGGREGATION_FUNCTION_COLUMN_KEY_OFFSET + 1, operands.size()); + } + + @Override + public List<ExpressionContext> getInputExpressions() { + ArrayList<ExpressionContext> expressionContexts = new ArrayList<>(); + expressionContexts.add(_childFunctionID); + expressionContexts.add(_childFunctionKeyInParent); + expressionContexts.addAll(_resultNameOperands); + return expressionContexts; + } + + @Override + public final AggregationResultHolder createAggregationResultHolder() { + return new DummyAggregationResultHolder(); + } + + @Override + public final GroupByResultHolder createGroupByResultHolder(int initialCapacity, int maxCapacity) { + return new DummyGroupByResultHolder(); + } + + @Override + public final void aggregate(int length, AggregationResultHolder aggregationResultHolder, + Map<ExpressionContext, BlockValSet> blockValSetMap) { + } + + @Override + public final void aggregateGroupBySV(int length, int[] groupKeyArray, GroupByResultHolder groupByResultHolder, + Map<ExpressionContext, BlockValSet> blockValSetMap) { + } + + @Override + public final void aggregateGroupByMV(int length, int[][] groupKeysArray, GroupByResultHolder groupByResultHolder, + Map<ExpressionContext, BlockValSet> blockValSetMap) { + } + + @Override + public final Long extractAggregationResult(AggregationResultHolder aggregationResultHolder) { + return 0L; + } + + @Override + public final Long extractGroupByResult(GroupByResultHolder groupByResultHolder, int groupKey) { + return 0L; + } + + @Override + public final Long merge(Long intermediateResult1, Long intermediateResult2) { + return 0L; + } + + @Override + public final DataSchema.ColumnDataType getIntermediateResultColumnType() { + return DataSchema.ColumnDataType.LONG; + } + + @Override + public final DataSchema.ColumnDataType getFinalResultColumnType() { + return DataSchema.ColumnDataType.UNKNOWN; + } + + @Override + public final Long extractFinalResult(Long longValue) { + return 0L; + } + + /** + * The name of the column as follows: + * CHILD_AGGREGATION_NAME_PREFIX + actual function type + operands + CHILD_AGGREGATION_SEPERATOR + * + actual function type + parent aggregation function id + CHILD_KEY_SEPERATOR + column key in parent function + * e.g. if the child aggregation function is "argmax(0,a,b,x)", the name of the column is + * "pinotchildaggregationargmax(a,b,x)@argmax0_x" + */ + @Override + public final String getResultColumnName() { + String type = getType().getName().toLowerCase(); + return CommonConstants.RewriterConstants.CHILD_AGGREGATION_NAME_PREFIX Review Comment: May be better to use StringBuilder in general but since this function will be called once per query, it should be fine for now -- 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. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org 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