This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 748648ef1eb branch-2.1: [fix](nereids) fix bug when sum0 distinct
appear in cte #45447 (#45511)
748648ef1eb is described below
commit 748648ef1eb73ae2d2c383662670f9c14972318f
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Dec 17 20:10:43 2024 +0800
branch-2.1: [fix](nereids) fix bug when sum0 distinct appear in cte #45447
(#45511)
Cherry-picked from #45447
Co-authored-by: feiniaofeiafei <[email protected]>
---
.../rules/implementation/AggregateStrategies.java | 6 ++++-
.../nereids_function_p0/agg_function/sum0_cte.out | 21 ++++++++++++++++
.../agg_function/sum0_cte.groovy | 29 ++++++++++++++++++++++
3 files changed, 55 insertions(+), 1 deletion(-)
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 738ddc2630f..1a0c655695f 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
@@ -54,6 +54,7 @@ import
org.apache.doris.nereids.trees.expressions.functions.agg.Max;
import org.apache.doris.nereids.trees.expressions.functions.agg.Min;
import
org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctCount;
import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
+import org.apache.doris.nereids.trees.expressions.functions.agg.Sum0;
import org.apache.doris.nereids.trees.expressions.functions.scalar.If;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
@@ -1773,6 +1774,8 @@ public class AggregateStrategies implements
ImplementationRuleFactory {
function.getArguments().subList(1,
function.arity()).toArray(new Expression[0]));
} else if (function instanceof Sum && function.isDistinct()) {
return ((Sum) function).convertToMultiDistinct();
+ } else if (function instanceof Sum0 && function.isDistinct()) {
+ return ((Sum0) function).convertToMultiDistinct();
} else if (function instanceof GroupConcat && function.isDistinct()) {
return ((GroupConcat) function).convertToMultiDistinct();
}
@@ -2036,7 +2039,8 @@ public class AggregateStrategies implements
ImplementationRuleFactory {
if (!func.isDistinct()) {
continue;
}
- if (!(func instanceof Count || func instanceof Sum || func
instanceof GroupConcat)) {
+ if (!(func instanceof Count || func instanceof Sum || func
instanceof GroupConcat
+ || func instanceof Sum0)) {
return false;
}
if (func.arity() <= 1) {
diff --git a/regression-test/data/nereids_function_p0/agg_function/sum0_cte.out
b/regression-test/data/nereids_function_p0/agg_function/sum0_cte.out
new file mode 100644
index 00000000000..3872d308917
--- /dev/null
+++ b/regression-test/data/nereids_function_p0/agg_function/sum0_cte.out
@@ -0,0 +1,21 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sum0_cte --
+78 78
+
+-- !shape --
+PhysicalCteAnchor ( cteId=CTEId#0 )
+--PhysicalCteProducer ( cteId=CTEId#0 )
+----PhysicalOlapScan[fn_test]
+--PhysicalResultSink
+----NestedLoopJoin[CROSS_JOIN]
+------hashAgg[DISTINCT_GLOBAL]
+--------hashAgg[DISTINCT_LOCAL]
+----------hashAgg[GLOBAL]
+------------hashAgg[LOCAL]
+--------------PhysicalCteConsumer ( cteId=CTEId#0 )
+------hashAgg[DISTINCT_GLOBAL]
+--------hashAgg[DISTINCT_LOCAL]
+----------hashAgg[GLOBAL]
+------------hashAgg[LOCAL]
+--------------PhysicalCteConsumer ( cteId=CTEId#0 )
+
diff --git
a/regression-test/suites/nereids_function_p0/agg_function/sum0_cte.groovy
b/regression-test/suites/nereids_function_p0/agg_function/sum0_cte.groovy
new file mode 100644
index 00000000000..a6f923baaf0
--- /dev/null
+++ b/regression-test/suites/nereids_function_p0/agg_function/sum0_cte.groovy
@@ -0,0 +1,29 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("sum0_cte") {
+ sql 'use regression_test_nereids_function_p0'
+ sql "set ignore_shape_nodes='PhysicalDistribute,PhysicalProject'"
+ qt_sum0_cte """with tmp as (select * from fn_test)
+ select * from (select sum0(distinct kint) from tmp ) t cross join (select
sum0(distinct ksint) from tmp) tt;
+ """
+ qt_shape """
+ explain shape plan
+ with tmp as (select * from fn_test)
+ select * from (select sum0(distinct kint) from tmp ) t cross join (select
sum0(distinct ksint) from tmp) tt;
+ """
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]