This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new b9776f8da17 branch-4.1: [fix](aggregate) Check all aggregate function
arguments #65537 (#65753)
b9776f8da17 is described below
commit b9776f8da178f0d04b9bf7d667c0a3f8b15677e2
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Jul 20 09:46:42 2026 +0800
branch-4.1: [fix](aggregate) Check all aggregate function arguments #65537
(#65753)
Cherry-picked from #65537
Co-authored-by: morrySnow <[email protected]>
---
.../doris/nereids/rules/analysis/NormalizeAggregate.java | 11 ++++++-----
.../doris/nereids/rules/analysis/NormalizeAggregateTest.java | 10 ++++++++++
.../suites/nereids_p0/aggregate/agg_group_concat.groovy | 8 ++++++++
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java
index c4f74f4ddb0..2cc864192fb 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java
@@ -171,6 +171,12 @@ public class NormalizeAggregate implements
RewriteRuleFactory, NormalizeToSlot {
ImmutableSet.Builder<Expression> needPushDownSelfExprs =
ImmutableSet.builder();
ImmutableSet.Builder<Expression> needPushDownInputs =
ImmutableSet.builder();
for (AggregateFunction aggFunc : aggFuncs.keySet()) {
+ for (Expression child : aggFunc.children()) {
+ if (ExpressionUtils.hasNonWindowAggregateFunction(child)) {
+ throw new AnalysisException(
+ "aggregate function cannot contain aggregate
parameters");
+ }
+ }
if (!aggFunc.isDistinct()) {
for (Expression arg : aggFunc.children()) {
// should not push down literal under aggregate
@@ -255,11 +261,6 @@ public class NormalizeAggregate implements
RewriteRuleFactory, NormalizeToSlot {
// normalize trivial-aggs by bottomProjects
List<Expression> normalizedAggFuncs =
bottomSlotContext.normalizeToUseSlotRef(SessionVarGuardExpr.getExprWithGuard(aggFuncs));
- if (normalizedAggFuncs.stream().anyMatch(agg ->
!agg.children().isEmpty()
- && agg.child(0).containsType(AggregateFunction.class))) {
- throw new AnalysisException(
- "aggregate function cannot contain aggregate parameters");
- }
// build normalized agg output
NormalizeToSlotContext normalizedAggFuncsToSlotContext =
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregateTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregateTest.java
index 647bd5914fb..78e66da8638 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregateTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregateTest.java
@@ -17,6 +17,7 @@
package org.apache.doris.nereids.rules.analysis;
+import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Add;
import org.apache.doris.nereids.trees.expressions.Alias;
import org.apache.doris.nereids.trees.expressions.ExprId;
@@ -736,6 +737,15 @@ public class NormalizeAggregateTest extends
TestWithFeService implements MemoPat
);
}
+ @Test
+ public void testAggregateOrderByExpressionCannotContainAggregateFunction()
{
+ String sql = "select group_concat(k order by sum(k)) as s "
+ + "from (select 1 as k union all select 2) t";
+ AnalysisException exception =
Assertions.assertThrows(AnalysisException.class,
+ () -> PlanChecker.from(connectContext).analyze(sql));
+ Assertions.assertEquals("aggregate function cannot contain aggregate
parameters", exception.getMessage());
+ }
+
@Test
public void testDistinctAggregateOrderByExpressionNeedPushDown() {
String sql = "select group_concat(distinct name order by id + no) from
t1";
diff --git
a/regression-test/suites/nereids_p0/aggregate/agg_group_concat.groovy
b/regression-test/suites/nereids_p0/aggregate/agg_group_concat.groovy
index f836796d265..cdf5d5292fa 100644
--- a/regression-test/suites/nereids_p0/aggregate/agg_group_concat.groovy
+++ b/regression-test/suites/nereids_p0/aggregate/agg_group_concat.groovy
@@ -107,6 +107,14 @@ suite("agg_group_concat") {
from (select 1 as k union all select 2) t;
"""
+ test {
+ sql """
+ select group_concat(k order by sum(k)) as s
+ from (select 1 as k union all select 2) t;
+ """
+ exception "aggregate function cannot contain aggregate parameters"
+ }
+
order_qt_group_concat_order_by_subquery """
select group_concat(kint order by (select 1), kint) as s
from agg_group_concat_table;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]