Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ private LogicalPlan normalizeAgg(LogicalAggregate<Plan> aggregate, Optional<Logi
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
Expand Down Expand Up @@ -257,11 +263,6 @@ private LogicalPlan normalizeAgg(LogicalAggregate<Plan> aggregate, Optional<Logi
// 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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -736,6 +737,15 @@ public void testAggregateOrderByExpressionNeedPushDown() {
);
}

@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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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;
Expand Down
Loading