diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java index fe7f9317b53fc3..eae17b1a99e486 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java @@ -363,7 +363,7 @@ && couldConvertToMulti(agg)) */ RuleType.FOUR_PHASE_AGGREGATE_WITH_DISTINCT_WITH_FULL_DISTRIBUTE.build( basePattern - .when(agg -> agg.everyDistinctArgumentsIsOne() && !agg.getGroupByExpressions().isEmpty()) + .when(agg -> agg.everyDistinctArgumentNumIsOne() && !agg.getGroupByExpressions().isEmpty()) .when(agg -> ImmutableSet.builder() .addAll(agg.getGroupByExpressions()) @@ -1870,7 +1870,7 @@ private List> fourPhaseAggregateWithDistin AggregateFunction nonDistinct = aggregateFunction .withDistinctAndChildren(false, ImmutableList.copyOf(aggChild)); AggregateExpression nonDistinctAggExpr = new AggregateExpression(nonDistinct, - distinctLocalParam, aggregateFunction.child(0)); + distinctLocalParam, aggregateFunction); return nonDistinctAggExpr; } else { needUpdateSlot.add(aggregateFunction); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Aggregate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Aggregate.java index ce182152dfe2df..acce8eef309de3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Aggregate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Aggregate.java @@ -70,8 +70,8 @@ default Set getDistinctArguments() { return distinctArguments.build(); } - /** everyDistinctAggregateFunctionIsOne */ - default boolean everyDistinctArgumentsIsOne() { + /** everyDistinctArgumentNumIsOne */ + default boolean everyDistinctArgumentNumIsOne() { AtomicBoolean hasDistinctArguments = new AtomicBoolean(false); for (NamedExpression outputExpression : getOutputExpressions()) { boolean distinctArgumentSizeNotOne = outputExpression.anyMatch(expr -> { diff --git a/regression-test/suites/nereids_syntax_p0/agg_4_phase.groovy b/regression-test/suites/nereids_syntax_p0/agg_4_phase.groovy index 19cac99c153fa7..d3b418660abe82 100644 --- a/regression-test/suites/nereids_syntax_p0/agg_4_phase.groovy +++ b/regression-test/suites/nereids_syntax_p0/agg_4_phase.groovy @@ -58,4 +58,6 @@ suite("agg_4_phase") { qt_4phase (test_sql) sql """select GROUP_CONCAT(distinct name, " ") from agg_4_phase_tbl;""" -} \ No newline at end of file + + sql """select /*+SET_VAR(disable_nereids_rules='TWO_PHASE_AGGREGATE_SINGLE_DISTINCT_TO_MULTI,THREE_PHASE_AGGREGATE_WITH_DISTINCT,FOUR_PHASE_AGGREGATE_WITH_DISTINCT')*/ GROUP_CONCAT(distinct name, " ") from agg_4_phase_tbl group by gender;""" +}