diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java index d4ed9c21776224..8653b93a88ea29 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java @@ -56,7 +56,6 @@ import org.apache.doris.nereids.rules.rewrite.CountLiteralRewrite; import org.apache.doris.nereids.rules.rewrite.CreatePartitionTopNFromWindow; import org.apache.doris.nereids.rules.rewrite.DeferMaterializeTopNResult; -import org.apache.doris.nereids.rules.rewrite.SplitMultiDistinct; import org.apache.doris.nereids.rules.rewrite.EliminateAggCaseWhen; import org.apache.doris.nereids.rules.rewrite.EliminateAggregate; import org.apache.doris.nereids.rules.rewrite.EliminateAssertNumRows; @@ -136,6 +135,7 @@ import org.apache.doris.nereids.rules.rewrite.SimplifyEncodeDecode; import org.apache.doris.nereids.rules.rewrite.SimplifyWindowExpression; import org.apache.doris.nereids.rules.rewrite.SplitLimit; +import org.apache.doris.nereids.rules.rewrite.SplitMultiDistinct; import org.apache.doris.nereids.rules.rewrite.SumLiteralRewrite; import org.apache.doris.nereids.rules.rewrite.TransposeSemiJoinAgg; import org.apache.doris.nereids.rules.rewrite.TransposeSemiJoinAggProject; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckMultiDistinct.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckMultiDistinct.java index bc6fd8437239af..dd76457c41181f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckMultiDistinct.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckMultiDistinct.java @@ -85,8 +85,8 @@ private LogicalAggregate checkDistinct(LogicalAggregate aggregat } if (distinctMultiColumns && distinctFunctionNum > 1) { - // throw new AnalysisException( - // "The query contains multi count distinct or sum distinct, each can't have multi columns"); + throw new AnalysisException( + "The query contains multi count distinct or sum distinct, each can't have multi columns"); } return aggregate; } diff --git a/regression-test/data/nereids_rules_p0/distinct_split/disitinct_split.out b/regression-test/data/nereids_rules_p0/distinct_split/disitinct_split.out index a1e600a15d7cea..2a1dd6fd9d6705 100644 --- a/regression-test/data/nereids_rules_p0/distinct_split/disitinct_split.out +++ b/regression-test/data/nereids_rules_p0/distinct_split/disitinct_split.out @@ -303,6 +303,12 @@ 2 3 3 2 3 1 3 2 3 2 2 3 3 2 3 1 3 2 3 2 +-- !2_agg_count_distinct -- +2 2 + +-- !3_agg_count_distinct -- +1 1 + -- !multi_count_without_gby -- PhysicalCteAnchor ( cteId=CTEId#0 ) --PhysicalCteProducer ( cteId=CTEId#0 ) @@ -450,6 +456,23 @@ PhysicalCteAnchor ( cteId=CTEId#0 ) --------hashAgg[LOCAL] ----------PhysicalCteConsumer ( cteId=CTEId#0 ) +-- !2_agg -- +PhysicalCteAnchor ( cteId=CTEId#0 ) +--PhysicalCteProducer ( cteId=CTEId#0 ) +----PhysicalOlapScan[test_distinct_multi] +--PhysicalResultSink +----hashAgg[GLOBAL] +------hashAgg[LOCAL] +--------hashJoin[INNER_JOIN] hashCondition=((.c = .c)) otherCondition=() +----------hashAgg[DISTINCT_LOCAL] +------------hashAgg[GLOBAL] +--------------hashAgg[LOCAL] +----------------PhysicalCteConsumer ( cteId=CTEId#0 ) +----------hashAgg[DISTINCT_LOCAL] +------------hashAgg[GLOBAL] +--------------hashAgg[LOCAL] +----------------PhysicalCteConsumer ( cteId=CTEId#0 ) + -- !multi_count_with_gby -- PhysicalResultSink --hashAgg[GLOBAL] @@ -468,3 +491,10 @@ PhysicalResultSink ----hashAgg[LOCAL] ------PhysicalOlapScan[test_distinct_multi] +-- !has_grouping -- +PhysicalResultSink +--hashAgg[GLOBAL] +----hashAgg[LOCAL] +------PhysicalRepeat +--------PhysicalOlapScan[test_distinct_multi] + diff --git a/regression-test/suites/nereids_rules_p0/distinct_split/disitinct_split.groovy b/regression-test/suites/nereids_rules_p0/distinct_split/disitinct_split.groovy index 60392f67e37710..02812b269a33eb 100644 --- a/regression-test/suites/nereids_rules_p0/distinct_split/disitinct_split.groovy +++ b/regression-test/suites/nereids_rules_p0/distinct_split/disitinct_split.groovy @@ -181,6 +181,10 @@ suite("distinct_split") { select * from tmp, (select sum(distinct a), count(distinct b,c) from test_distinct_multi) t, (select sum(distinct a), count(distinct b,c) from test_distinct_multi group by d) tt order by 1,2,3,4,5,6,7,8,9,10 """ + // multi aggregate + qt_2_agg_count_distinct """select count(distinct c1) c3, count(distinct c2) c4 from (select count(distinct a,b) c1, count(distinct a,c) c2 from test_distinct_multi group by c) t""" + qt_3_agg_count_distinct """select count(distinct c3), count(distinct c4) from (select count(distinct c1) c3, count(distinct c2) c4 from (select count(distinct a,b) c1, count(distinct a,c) c2 from test_distinct_multi group by c) t) tt""" + // shape sql "SET ignore_shape_nodes='PhysicalDistribute,PhysicalProject'" qt_multi_count_without_gby """explain shape plan select count(distinct b), count(distinct a) from test_distinct_multi""" @@ -191,9 +195,16 @@ suite("distinct_split") { qt_three_count_mulitcols_without_gby """explain shape plan select count(distinct b,c), count(distinct a,b), count(distinct a,b,c) from test_distinct_multi""" qt_four_count_mulitcols_with_gby """explain shape plan select count(distinct b,c), count(distinct a,b),count(distinct b,c,d), count(distinct a,b,c) from test_distinct_multi group by d""" qt_has_other_func "explain shape plan select count(distinct b), count(distinct a), max(b),sum(c),min(a) from test_distinct_multi" + qt_2_agg """explain shape plan select max(c1), min(c2) from (select count(distinct a,b) c1, count(distinct a,c) c2 from test_distinct_multi group by c) t""" // should not rewrite qt_multi_count_with_gby """explain shape plan select count(distinct b), count(distinct a) from test_distinct_multi group by c""" qt_multi_sum_with_gby """explain shape plan select sum(distinct b), sum(distinct a) from test_distinct_multi group by c""" qt_sum_count_with_gby """explain shape plan select sum(distinct b), count(distinct a) from test_distinct_multi group by a""" + qt_has_grouping """explain shape plan select count(distinct b), count(distinct a) from test_distinct_multi group by grouping sets((a,b),(c));""" + test { + sql """select count(distinct a,b), count(distinct a) from test_distinct_multi + group by grouping sets((a,b),(c));""" + exception "The query contains multi count distinct or sum distinct, each can't have multi columns" + } } \ No newline at end of file