[fix](fe) Check all aggregate function arguments#65537
Conversation
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: NormalizeAggregate only checked the first child of each aggregate function for nested aggregate functions. Aggregate functions in later arguments, such as SUM in the ORDER BY argument of GROUP_CONCAT, could bypass analysis validation. Check every aggregate child and add FE unit and regression coverage for the invalid query.
### Release note
Reject nested aggregate functions in every aggregate function argument.
### Check List (For Author)
- Test: Unit Test and Regression test
- Unit Test: NormalizeAggregateTest
- Regression test: query_p0/aggregate/agg_group_concat
- Behavior changed: Yes, invalid nested aggregate functions in non-first arguments are rejected during analysis
- Does this need documentation: No
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
/review |
|
run buildall |
There was a problem hiding this comment.
I found one correctness issue in the aggregate-parameter validation.
Critical checkpoints:
- Goal: the PR intends to reject aggregate functions nested in aggregate parameters. It covers the simple non-distinct
group_concat(k order by sum(k))case, but the validation still runs after some aggregate-containing children can be normalized to slots. - Scope/focus: the code change is small, but the affected normalization path has parallel distinct and pushdown-triggered order-key branches.
- Concurrency/lifecycle/config/persistence/FE-BE protocol: not involved.
- Parallel paths: issue found in distinct non-slot children and non-distinct order keys containing pushdown-triggering expressions.
- Tests: the new FE and regression tests use the right expected-error pattern, but they only cover the simple non-distinct order-key case and miss the variants in the inline comment.
- User focus: no additional user-provided focus was supplied.
Validation was static only. I did not run builds or tests because this review prompt forbids builds/code modifications, and this checkout is not worktree-initialized and lacks thirdparty/installed / thirdparty/installed/bin/protoc.
| bottomSlotContext.normalizeToUseSlotRef(SessionVarGuardExpr.getExprWithGuard(aggFuncs)); | ||
| if (normalizedAggFuncs.stream().anyMatch(agg -> !agg.children().isEmpty() | ||
| && agg.child(0).containsType(AggregateFunction.class))) { | ||
| && agg.children().stream().anyMatch(e -> e.containsType(AggregateFunction.class)))) { |
There was a problem hiding this comment.
This check still runs too late for children that were put into needPushDownSelfExprs. For example, group_concat(distinct k order by sum(k)) unwraps the order key in the distinct branch and maps sum(k) to a bottom-project alias slot before this block runs; similarly, count(distinct sum(k)) or an order key like sum(k) + row_number() over(...) can be replaced by a slot first. After normalizeToUseSlotRef, the aggregate child no longer contains an AggregateFunction, so this check misses the nested aggregate and may only fail later as an aggregate pushed into the wrong plan node. Please validate the original aggregate children/order-key children for non-window aggregate functions before any slot normalization, and add coverage for the distinct and pushdown-triggered variants.
TPC-H: Total hot run time: 29293 ms |
TPC-DS: Total hot run time: 180871 ms |
ClickBench: Total hot run time: 25.04 s |
FE UT Coverage ReportIncrement line coverage |
FE Regression Coverage ReportIncrement line coverage |
What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: NormalizeAggregate only checked the first child of each aggregate function for nested aggregate functions. Aggregate functions in later arguments, such as SUM in the ORDER BY argument of GROUP_CONCAT, could bypass analysis validation. Check every aggregate child and add FE unit and regression coverage for the invalid query.
Release note
Reject nested aggregate functions in every aggregate function argument.
Check List (For Author)