You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "Jackie-Jiang (via GitHub)" <gi...@apache.org> on 2023/09/18 23:59:31 UTC
[GitHub] [pinot] Jackie-Jiang opened a new pull request, #11617: In multi-stage aggregate, directly store column index as identifier
Jackie-Jiang opened a new pull request, #11617:
URL: https://github.com/apache/pinot/pull/11617
Avoid constructing the column name to index map and converting back and forth
--
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-unsubscribe@pinot.apache.org
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
[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #11617: In multi-stage aggregate, directly store column index as identifier
Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #11617:
URL: https://github.com/apache/pinot/pull/11617#discussion_r1330605596
##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/AggregateOperator.java:
##########
@@ -205,90 +196,78 @@ private TransferableBlock consumeAggregation() {
return block;
}
- private List<FunctionContext> getFunctionContexts(List<RexExpression> aggCalls) {
+ private AggregationFunction<?, ?>[] getAggFunctions(List<RexExpression> aggCalls,
+ Map<Integer, Map<Integer, Literal>> literalArgumentsMap) {
int numFunctions = aggCalls.size();
- List<FunctionContext> functionContexts = new ArrayList<>(numFunctions);
+ AggregationFunction<?, ?>[] aggFunctions = new AggregationFunction[numFunctions];
for (int i = 0; i < numFunctions; i++) {
RexExpression.FunctionCall functionCall = (RexExpression.FunctionCall) aggCalls.get(i);
- FunctionContext funcContext = convertRexExpressionsToFunctionContext(i, functionCall);
- functionContexts.add(funcContext);
+ Map<Integer, Literal> literalArguments = literalArgumentsMap.getOrDefault(i, Collections.emptyMap());
+ aggFunctions[i] = getAggFunction(functionCall, literalArguments);
}
- return functionContexts;
+ return aggFunctions;
}
- private FunctionContext convertRexExpressionsToFunctionContext(int aggIdx,
- RexExpression.FunctionCall aggFunctionCall) {
- // Extract details from RexExpression aggFunctionCall.
- String functionName = aggFunctionCall.getFunctionName();
- List<RexExpression> functionOperands = aggFunctionCall.getFunctionOperands();
-
- List<ExpressionContext> aggArguments = new ArrayList<>();
- for (int argIdx = 0; argIdx < functionOperands.size(); argIdx++) {
- RexExpression operand = functionOperands.get(argIdx);
- ExpressionContext exprContext = convertRexExpressionToExpressionContext(aggIdx, argIdx, operand);
- aggArguments.add(exprContext);
+ private AggregationFunction<?, ?> getAggFunction(RexExpression.FunctionCall functionCall,
+ Map<Integer, Literal> literalArguments) {
+ String functionName = functionCall.getFunctionName();
+ List<RexExpression> operands = functionCall.getFunctionOperands();
+ int numArguments = operands.size();
+ if (numArguments == 0) {
+ Preconditions.checkState(functionName.equals("COUNT"),
+ "Aggregate function without argument must be COUNT, got: %s", functionName);
+ return COUNT_STAR_AGG_FUNCTION;
}
- // add additional arguments for aggFunctionCall
+ // For intermediate aggregation, we might need to append the arguments to match the signature of the aggregation
+ int numExpectedArguments = numArguments;
if (_aggType.isInputIntermediateFormat()) {
- rewriteAggArgumentForIntermediateInput(aggArguments, aggIdx);
- }
- // This can only be true for COUNT aggregation functions on intermediate stage.
- // The literal value here does not matter. We create a dummy literal here just so that the count aggregation
- // has some column to process.
- if (aggArguments.isEmpty()) {
- aggArguments.add(ExpressionContext.forLiteralContext(FieldSpec.DataType.STRING, "__PLACEHOLDER__"));
- }
-
- return new FunctionContext(FunctionContext.Type.AGGREGATION, functionName, aggArguments);
- }
-
- private void rewriteAggArgumentForIntermediateInput(List<ExpressionContext> aggArguments, int aggIdx) {
- Map<Integer, Literal> aggCallSignature = _aggCallSignatureMap.get(aggIdx);
- if (aggCallSignature != null && !aggCallSignature.isEmpty()) {
- int argListSize = aggCallSignature.get(-1).getIntValue();
- for (int argIdx = 1; argIdx < argListSize; argIdx++) {
- Literal aggIdxLiteral = aggCallSignature.get(argIdx);
- if (aggIdxLiteral != null) {
- aggArguments.add(ExpressionContext.forLiteralContext(aggIdxLiteral));
- } else {
- aggArguments.add(ExpressionContext.forIdentifier("__PLACEHOLDER__"));
- }
+ Literal literal = literalArguments.get(-1);
+ if (literal != null) {
+ numExpectedArguments = literal.getIntValue();
}
}
- }
- private ExpressionContext convertRexExpressionToExpressionContext(int aggIdx, int argIdx, RexExpression rexExpr) {
- ExpressionContext exprContext;
- if (_aggCallSignatureMap.get(aggIdx) != null && _aggCallSignatureMap.get(aggIdx).get(argIdx) != null) {
- return ExpressionContext.forLiteralContext(_aggCallSignatureMap.get(aggIdx).get(argIdx));
- }
-
- // This is used only for aggregation arguments and groupby columns. The rexExpression can never be a function type.
- switch (rexExpr.getKind()) {
- case INPUT_REF: {
- RexExpression.InputRef inputRef = (RexExpression.InputRef) rexExpr;
- int identifierIndex = inputRef.getIndex();
- String columnName = _inputSchema.getColumnName(identifierIndex);
- // Calcite generates unique column names for aggregation functions. For example, select avg(col1), sum(col1)
- // will generate names $f0 and $f1 for avg and sum respectively. We use a map to store the name -> index
- // mapping to extract the required column value from row-based container and fetch the input datatype for the
- // column.
- _colNameToIndexMap.put(columnName, identifierIndex);
- exprContext = ExpressionContext.forIdentifier(columnName);
- break;
+ List<ExpressionContext> arguments = new ArrayList<>(numExpectedArguments);
+ for (int i = 0; i < numExpectedArguments; i++) {
+ Literal literal = literalArguments.get(i);
+ if (literal != null) {
+ arguments.add(ExpressionContext.forLiteralContext(literal));
+ continue;
+ }
+ if (i >= numArguments) {
Review Comment:
Separated the code path for raw input vs intermediate input
--
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-unsubscribe@pinot.apache.org
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
[GitHub] [pinot] codecov-commenter commented on pull request #11617: In multi-stage aggregate, directly store column index as identifier
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #11617:
URL: https://github.com/apache/pinot/pull/11617#issuecomment-1724667548
## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/11617?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#11617](https://app.codecov.io/gh/apache/pinot/pull/11617?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (e50179d) into [master](https://app.codecov.io/gh/apache/pinot/commit/7fb47f062d022fd95319a984aec2c1155cbe77d4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (7fb47f0) will **decrease** coverage by `35.57%`.
> Report is 4 commits behind head on master.
> The diff coverage is `0.00%`.
> :exclamation: Current head e50179d differs from pull request most recent head 01c1200. Consider uploading reports for the commit 01c1200 to get more accurate results
```diff
@@ Coverage Diff @@
## master #11617 +/- ##
=============================================
- Coverage 50.04% 14.48% -35.57%
- Complexity 6 201 +195
=============================================
Files 2250 2325 +75
Lines 121155 124859 +3704
Branches 18585 19142 +557
=============================================
- Hits 60636 18080 -42556
- Misses 56429 105258 +48829
+ Partials 4090 1521 -2569
```
| [Flag](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [integration](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration1](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration2](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [java-11](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [java-17](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [java-20](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `14.48% <0.00%> (-35.44%)` | :arrow_down: |
| [temurin](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `14.48% <0.00%> (-35.57%)` | :arrow_down: |
| [unittests](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `14.48% <0.00%> (-52.79%)` | :arrow_down: |
| [unittests1](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unittests2](https://app.codecov.io/gh/apache/pinot/pull/11617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `14.48% <0.00%> (?)` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Files Changed](https://app.codecov.io/gh/apache/pinot/pull/11617?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...inot/query/runtime/operator/AggregateOperator.java](https://app.codecov.io/gh/apache/pinot/pull/11617?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9vcGVyYXRvci9BZ2dyZWdhdGVPcGVyYXRvci5qYXZh) | `0.00% <0.00%> (-83.16%)` | :arrow_down: |
| [...untime/operator/MultistageAggregationExecutor.java](https://app.codecov.io/gh/apache/pinot/pull/11617?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9vcGVyYXRvci9NdWx0aXN0YWdlQWdncmVnYXRpb25FeGVjdXRvci5qYXZh) | `0.00% <0.00%> (-89.86%)` | :arrow_down: |
| [...ry/runtime/operator/MultistageGroupByExecutor.java](https://app.codecov.io/gh/apache/pinot/pull/11617?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9vcGVyYXRvci9NdWx0aXN0YWdlR3JvdXBCeUV4ZWN1dG9yLmphdmE=) | `0.00% <0.00%> (-91.91%)` | :arrow_down: |
| [.../pinot/query/runtime/plan/PhysicalPlanVisitor.java](https://app.codecov.io/gh/apache/pinot/pull/11617?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9wbGFuL1BoeXNpY2FsUGxhblZpc2l0b3IuamF2YQ==) | `0.00% <0.00%> (-91.84%)` | :arrow_down: |
... and [1980 files with indirect coverage changes](https://app.codecov.io/gh/apache/pinot/pull/11617/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
--
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-unsubscribe@pinot.apache.org
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
[GitHub] [pinot] walterddr commented on a diff in pull request #11617: In multi-stage aggregate, directly store column index as identifier
Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr commented on code in PR #11617:
URL: https://github.com/apache/pinot/pull/11617#discussion_r1330404415
##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/AggregateOperator.java:
##########
@@ -205,90 +196,78 @@ private TransferableBlock consumeAggregation() {
return block;
}
- private List<FunctionContext> getFunctionContexts(List<RexExpression> aggCalls) {
+ private AggregationFunction<?, ?>[] getAggFunctions(List<RexExpression> aggCalls,
+ Map<Integer, Map<Integer, Literal>> literalArgumentsMap) {
int numFunctions = aggCalls.size();
- List<FunctionContext> functionContexts = new ArrayList<>(numFunctions);
+ AggregationFunction<?, ?>[] aggFunctions = new AggregationFunction[numFunctions];
for (int i = 0; i < numFunctions; i++) {
RexExpression.FunctionCall functionCall = (RexExpression.FunctionCall) aggCalls.get(i);
- FunctionContext funcContext = convertRexExpressionsToFunctionContext(i, functionCall);
- functionContexts.add(funcContext);
+ Map<Integer, Literal> literalArguments = literalArgumentsMap.getOrDefault(i, Collections.emptyMap());
+ aggFunctions[i] = getAggFunction(functionCall, literalArguments);
}
- return functionContexts;
+ return aggFunctions;
}
- private FunctionContext convertRexExpressionsToFunctionContext(int aggIdx,
- RexExpression.FunctionCall aggFunctionCall) {
- // Extract details from RexExpression aggFunctionCall.
- String functionName = aggFunctionCall.getFunctionName();
- List<RexExpression> functionOperands = aggFunctionCall.getFunctionOperands();
-
- List<ExpressionContext> aggArguments = new ArrayList<>();
- for (int argIdx = 0; argIdx < functionOperands.size(); argIdx++) {
- RexExpression operand = functionOperands.get(argIdx);
- ExpressionContext exprContext = convertRexExpressionToExpressionContext(aggIdx, argIdx, operand);
- aggArguments.add(exprContext);
+ private AggregationFunction<?, ?> getAggFunction(RexExpression.FunctionCall functionCall,
+ Map<Integer, Literal> literalArguments) {
+ String functionName = functionCall.getFunctionName();
+ List<RexExpression> operands = functionCall.getFunctionOperands();
+ int numArguments = operands.size();
+ if (numArguments == 0) {
+ Preconditions.checkState(functionName.equals("COUNT"),
+ "Aggregate function without argument must be COUNT, got: %s", functionName);
+ return COUNT_STAR_AGG_FUNCTION;
}
- // add additional arguments for aggFunctionCall
+ // For intermediate aggregation, we might need to append the arguments to match the signature of the aggregation
+ int numExpectedArguments = numArguments;
if (_aggType.isInputIntermediateFormat()) {
- rewriteAggArgumentForIntermediateInput(aggArguments, aggIdx);
- }
- // This can only be true for COUNT aggregation functions on intermediate stage.
- // The literal value here does not matter. We create a dummy literal here just so that the count aggregation
- // has some column to process.
- if (aggArguments.isEmpty()) {
- aggArguments.add(ExpressionContext.forLiteralContext(FieldSpec.DataType.STRING, "__PLACEHOLDER__"));
- }
-
- return new FunctionContext(FunctionContext.Type.AGGREGATION, functionName, aggArguments);
- }
-
- private void rewriteAggArgumentForIntermediateInput(List<ExpressionContext> aggArguments, int aggIdx) {
- Map<Integer, Literal> aggCallSignature = _aggCallSignatureMap.get(aggIdx);
- if (aggCallSignature != null && !aggCallSignature.isEmpty()) {
- int argListSize = aggCallSignature.get(-1).getIntValue();
- for (int argIdx = 1; argIdx < argListSize; argIdx++) {
- Literal aggIdxLiteral = aggCallSignature.get(argIdx);
- if (aggIdxLiteral != null) {
- aggArguments.add(ExpressionContext.forLiteralContext(aggIdxLiteral));
- } else {
- aggArguments.add(ExpressionContext.forIdentifier("__PLACEHOLDER__"));
- }
+ Literal literal = literalArguments.get(-1);
+ if (literal != null) {
+ numExpectedArguments = literal.getIntValue();
}
}
- }
- private ExpressionContext convertRexExpressionToExpressionContext(int aggIdx, int argIdx, RexExpression rexExpr) {
- ExpressionContext exprContext;
- if (_aggCallSignatureMap.get(aggIdx) != null && _aggCallSignatureMap.get(aggIdx).get(argIdx) != null) {
- return ExpressionContext.forLiteralContext(_aggCallSignatureMap.get(aggIdx).get(argIdx));
- }
-
- // This is used only for aggregation arguments and groupby columns. The rexExpression can never be a function type.
- switch (rexExpr.getKind()) {
- case INPUT_REF: {
- RexExpression.InputRef inputRef = (RexExpression.InputRef) rexExpr;
- int identifierIndex = inputRef.getIndex();
- String columnName = _inputSchema.getColumnName(identifierIndex);
- // Calcite generates unique column names for aggregation functions. For example, select avg(col1), sum(col1)
- // will generate names $f0 and $f1 for avg and sum respectively. We use a map to store the name -> index
- // mapping to extract the required column value from row-based container and fetch the input datatype for the
- // column.
- _colNameToIndexMap.put(columnName, identifierIndex);
- exprContext = ExpressionContext.forIdentifier(columnName);
- break;
+ List<ExpressionContext> arguments = new ArrayList<>(numExpectedArguments);
+ for (int i = 0; i < numExpectedArguments; i++) {
+ Literal literal = literalArguments.get(i);
+ if (literal != null) {
+ arguments.add(ExpressionContext.forLiteralContext(literal));
+ continue;
+ }
+ if (i >= numArguments) {
Review Comment:
intermediate agg always have 1 real-argument (it cannot even be 0 b/c count would've been converted to SUM), and the rest are placeholders, why do we need to check the numArguments again here? simply do the loop with `for (int i = 1 ...` should be suffice?
--
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-unsubscribe@pinot.apache.org
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
[GitHub] [pinot] walterddr commented on a diff in pull request #11617: In multi-stage aggregate, directly store column index as identifier
Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr commented on code in PR #11617:
URL: https://github.com/apache/pinot/pull/11617#discussion_r1330404415
##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/AggregateOperator.java:
##########
@@ -205,90 +196,78 @@ private TransferableBlock consumeAggregation() {
return block;
}
- private List<FunctionContext> getFunctionContexts(List<RexExpression> aggCalls) {
+ private AggregationFunction<?, ?>[] getAggFunctions(List<RexExpression> aggCalls,
+ Map<Integer, Map<Integer, Literal>> literalArgumentsMap) {
int numFunctions = aggCalls.size();
- List<FunctionContext> functionContexts = new ArrayList<>(numFunctions);
+ AggregationFunction<?, ?>[] aggFunctions = new AggregationFunction[numFunctions];
for (int i = 0; i < numFunctions; i++) {
RexExpression.FunctionCall functionCall = (RexExpression.FunctionCall) aggCalls.get(i);
- FunctionContext funcContext = convertRexExpressionsToFunctionContext(i, functionCall);
- functionContexts.add(funcContext);
+ Map<Integer, Literal> literalArguments = literalArgumentsMap.getOrDefault(i, Collections.emptyMap());
+ aggFunctions[i] = getAggFunction(functionCall, literalArguments);
}
- return functionContexts;
+ return aggFunctions;
}
- private FunctionContext convertRexExpressionsToFunctionContext(int aggIdx,
- RexExpression.FunctionCall aggFunctionCall) {
- // Extract details from RexExpression aggFunctionCall.
- String functionName = aggFunctionCall.getFunctionName();
- List<RexExpression> functionOperands = aggFunctionCall.getFunctionOperands();
-
- List<ExpressionContext> aggArguments = new ArrayList<>();
- for (int argIdx = 0; argIdx < functionOperands.size(); argIdx++) {
- RexExpression operand = functionOperands.get(argIdx);
- ExpressionContext exprContext = convertRexExpressionToExpressionContext(aggIdx, argIdx, operand);
- aggArguments.add(exprContext);
+ private AggregationFunction<?, ?> getAggFunction(RexExpression.FunctionCall functionCall,
+ Map<Integer, Literal> literalArguments) {
+ String functionName = functionCall.getFunctionName();
+ List<RexExpression> operands = functionCall.getFunctionOperands();
+ int numArguments = operands.size();
+ if (numArguments == 0) {
+ Preconditions.checkState(functionName.equals("COUNT"),
+ "Aggregate function without argument must be COUNT, got: %s", functionName);
+ return COUNT_STAR_AGG_FUNCTION;
}
- // add additional arguments for aggFunctionCall
+ // For intermediate aggregation, we might need to append the arguments to match the signature of the aggregation
+ int numExpectedArguments = numArguments;
if (_aggType.isInputIntermediateFormat()) {
- rewriteAggArgumentForIntermediateInput(aggArguments, aggIdx);
- }
- // This can only be true for COUNT aggregation functions on intermediate stage.
- // The literal value here does not matter. We create a dummy literal here just so that the count aggregation
- // has some column to process.
- if (aggArguments.isEmpty()) {
- aggArguments.add(ExpressionContext.forLiteralContext(FieldSpec.DataType.STRING, "__PLACEHOLDER__"));
- }
-
- return new FunctionContext(FunctionContext.Type.AGGREGATION, functionName, aggArguments);
- }
-
- private void rewriteAggArgumentForIntermediateInput(List<ExpressionContext> aggArguments, int aggIdx) {
- Map<Integer, Literal> aggCallSignature = _aggCallSignatureMap.get(aggIdx);
- if (aggCallSignature != null && !aggCallSignature.isEmpty()) {
- int argListSize = aggCallSignature.get(-1).getIntValue();
- for (int argIdx = 1; argIdx < argListSize; argIdx++) {
- Literal aggIdxLiteral = aggCallSignature.get(argIdx);
- if (aggIdxLiteral != null) {
- aggArguments.add(ExpressionContext.forLiteralContext(aggIdxLiteral));
- } else {
- aggArguments.add(ExpressionContext.forIdentifier("__PLACEHOLDER__"));
- }
+ Literal literal = literalArguments.get(-1);
+ if (literal != null) {
+ numExpectedArguments = literal.getIntValue();
}
}
- }
- private ExpressionContext convertRexExpressionToExpressionContext(int aggIdx, int argIdx, RexExpression rexExpr) {
- ExpressionContext exprContext;
- if (_aggCallSignatureMap.get(aggIdx) != null && _aggCallSignatureMap.get(aggIdx).get(argIdx) != null) {
- return ExpressionContext.forLiteralContext(_aggCallSignatureMap.get(aggIdx).get(argIdx));
- }
-
- // This is used only for aggregation arguments and groupby columns. The rexExpression can never be a function type.
- switch (rexExpr.getKind()) {
- case INPUT_REF: {
- RexExpression.InputRef inputRef = (RexExpression.InputRef) rexExpr;
- int identifierIndex = inputRef.getIndex();
- String columnName = _inputSchema.getColumnName(identifierIndex);
- // Calcite generates unique column names for aggregation functions. For example, select avg(col1), sum(col1)
- // will generate names $f0 and $f1 for avg and sum respectively. We use a map to store the name -> index
- // mapping to extract the required column value from row-based container and fetch the input datatype for the
- // column.
- _colNameToIndexMap.put(columnName, identifierIndex);
- exprContext = ExpressionContext.forIdentifier(columnName);
- break;
+ List<ExpressionContext> arguments = new ArrayList<>(numExpectedArguments);
+ for (int i = 0; i < numExpectedArguments; i++) {
+ Literal literal = literalArguments.get(i);
+ if (literal != null) {
+ arguments.add(ExpressionContext.forLiteralContext(literal));
+ continue;
+ }
+ if (i >= numArguments) {
Review Comment:
intermediate agg always have 1 real-argument (it cannot even be 0 b/c count would've been converted to SUM), and the rest are placeholders, why do we need to check the numArguments again here? simply do the for `int i = 1` should be suffice?
--
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-unsubscribe@pinot.apache.org
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
[GitHub] [pinot] Jackie-Jiang merged pull request #11617: In multi-stage aggregate, directly store column index as identifier
Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang merged PR #11617:
URL: https://github.com/apache/pinot/pull/11617
--
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-unsubscribe@pinot.apache.org
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