jasperjiaguo commented on code in PR #10636: URL: https://github.com/apache/pinot/pull/10636#discussion_r1185422938
########## pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/ChildAggregationFunction.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.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; + + +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 + */ + @Override + public final String getResultColumnName() { + String type = getType().getName().toLowerCase(); + return CommonConstants.RewriterConstants.CHILD_AGGREGATION_NAME_PREFIX + // above is the prefix for all child aggregation functions + + + type + "(" + _resultNameOperands.stream().map(ExpressionContext::toString) + .collect(Collectors.joining(",")) + ")" + // above is the actual child aggregation function name we want to return to the user + + + CommonConstants.RewriterConstants.CHILD_AGGREGATION_SEPERATOR + + type + + _childFunctionID.getLiteral().getStringValue() + + CommonConstants.RewriterConstants.CHILD_KEY_SEPERATOR + + _childFunctionKeyInParent.toString(); + // above is the column key in the parent aggregation function + } + + @Override + public String toExplainString() { Review Comment: added ########## pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/ParentAggregationFunction.java: ########## @@ -0,0 +1,63 @@ +/** + * 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.List; +import org.apache.pinot.common.request.context.ExpressionContext; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.core.query.aggregation.utils.ParentAggregationFunctionResultObject; +import org.apache.pinot.spi.utils.CommonConstants; + + +public abstract class ParentAggregationFunction<I, F extends ParentAggregationFunctionResultObject> + implements AggregationFunction<I, F> { + + protected static final int PARENT_AGGREGATION_FUNCTION_ID_OFFSET = 0; + protected List<ExpressionContext> _arguments; + + ParentAggregationFunction(List<ExpressionContext> arguments) { + _arguments = arguments; + } + + @Override + public final DataSchema.ColumnDataType getFinalResultColumnType() { + return DataSchema.ColumnDataType.OBJECT; + } + + // The name of the column is the prefix of the parent aggregation function + the name of the + // aggregation function + the id of the parent aggregation function + @Override + public String getResultColumnName() { + return CommonConstants.RewriterConstants.PARENT_AGGREGATION_NAME_PREFIX + + getType().getName().toLowerCase() + + _arguments.get(PARENT_AGGREGATION_FUNCTION_ID_OFFSET).getLiteral().getIntValue(); + } + + public String toExplainString() { Review Comment: added -- 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