Skip to content
Merged
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 @@ -22,15 +22,10 @@
import org.apache.doris.nereids.rules.RuleType;
import org.apache.doris.nereids.trees.expressions.OrderExpression;
import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
import org.apache.doris.nereids.trees.expressions.functions.agg.Avg;
import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
import org.apache.doris.nereids.trees.expressions.functions.agg.GroupConcat;
import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
import org.apache.doris.nereids.trees.expressions.functions.agg.SupportMultiDistinct;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;

import com.google.common.collect.ImmutableSet;

/**
* If there are multiple distinct aggregate functions that cannot
* be transformed into multi_distinct, an error is reported.
Expand All @@ -41,9 +36,6 @@
* - group_concat -> MULTI_DISTINCT_GROUP_CONCAT
*/
public class CheckMultiDistinct extends OneRewriteRuleFactory {
private final ImmutableSet<Class<? extends AggregateFunction>> supportedFunctions =
ImmutableSet.of(Count.class, Sum.class, Avg.class, GroupConcat.class);

@Override
public Rule build() {
return logicalAggregate().then(agg -> checkDistinct(agg)).toRule(RuleType.CHECK_ANALYSIS);
Expand All @@ -53,7 +45,7 @@ private LogicalAggregate checkDistinct(LogicalAggregate<? extends Plan> aggregat
if (aggregate.getDistinctArguments().size() > 1) {

for (AggregateFunction func : aggregate.getAggregateFunctions()) {
if (func.isDistinct() && !supportedFunctions.contains(func.getClass())) {
if (func.isDistinct() && !(func instanceof SupportMultiDistinct)) {
throw new AnalysisException(func.toString() + " can't support multi distinct.");
}
}
Expand Down
12 changes: 12 additions & 0 deletions regression-test/data/nereids_syntax_p0/analyze_agg.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --

-- !test_sum0 --
0 0
0 3
0 5
0 7
5 21

-- !test_sum0_all_null --
0 3
0 5
0 7

11 changes: 11 additions & 0 deletions regression-test/suites/nereids_syntax_p0/analyze_agg.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,15 @@ suite("analyze_agg") {
1,
x
"""

sql "drop table if exists test_sum0_multi_distinct_with_group_by"
sql "create table test_sum0_multi_distinct_with_group_by (a int, b int, c int) distributed by hash(a) properties('replication_num'='1');"
sql """
INSERT INTO test_sum0_multi_distinct_with_group_by VALUES
(1, NULL, 3), (2, NULL, 5), (3, NULL, 7),
(4,5,6),(4,5,7),(4,5,8),
(5,0,0),(5,0,0),(5,0,0);
"""
qt_test_sum0 "select sum0(distinct b),sum(distinct c) from test_sum0_multi_distinct_with_group_by group by a order by 1,2"
qt_test_sum0_all_null "select sum0(distinct b),sum(distinct c) from test_sum0_multi_distinct_with_group_by where a in (1,2,3) group by a order by 1,2"
}