From a1bf00e5eafafbd5714c25df8c65de365e5ebb9f Mon Sep 17 00:00:00 2001 From: starocean999 <40539150+starocean999@users.noreply.github.com> Date: Wed, 7 Feb 2024 22:24:13 +0800 Subject: [PATCH] [fix](nereids)aggregate function cannot contain aggregate parameters (#30928) --- .../doris/nereids/rules/analysis/NormalizeAggregate.java | 6 ++++++ .../suites/nereids_p0/aggregate/aggregate.groovy | 7 +++++++ 2 files changed, 13 insertions(+) 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 0e7dc51bab..f7604e3005 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 @@ -17,6 +17,7 @@ package org.apache.doris.nereids.rules.analysis; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.rules.Rule; import org.apache.doris.nereids.rules.RuleType; import org.apache.doris.nereids.rules.rewrite.NormalizeToSlot; @@ -220,6 +221,11 @@ public class NormalizeAggregate implements RewriteRuleFactory, NormalizeToSlot { // normalize trival-aggs by bottomProjects List normalizedAggFuncs = bottomSlotContext.normalizeToUseSlotRef(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/regression-test/suites/nereids_p0/aggregate/aggregate.groovy b/regression-test/suites/nereids_p0/aggregate/aggregate.groovy index 6f63b146cb..e9cb3b31b8 100644 --- a/regression-test/suites/nereids_p0/aggregate/aggregate.groovy +++ b/regression-test/suites/nereids_p0/aggregate/aggregate.groovy @@ -336,4 +336,11 @@ suite("aggregate") { """ exception "java.sql.SQLException: errCode = 2, detailMessage = k2 not in agg's output" } + + test { + sql """ + SELECT sum(avg(k1)) FROM tempbaseall; + """ + exception "aggregate function cannot contain aggregate parameters" + } }