This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 2892c7ff13e branch-3.1:  [fix][nereids] fix split count distinct for 
null can't join #46563 (#53782)
2892c7ff13e is described below

commit 2892c7ff13edff0535059c59f67d7408f70b732d
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Jul 24 16:22:15 2025 +0800

    branch-3.1:  [fix][nereids] fix split count distinct for null can't join 
#46563 (#53782)
    
    Cherry-picked from #46563
    
    Co-authored-by: shee <[email protected]>
    Co-authored-by: garenshi <[email protected]>
---
 .../nereids/rules/rewrite/SplitMultiDistinct.java     |   6 +++---
 .../nereids/rules/rewrite/SplitMultiDistinctTest.java |   4 ++++
 .../distinct_split/disitinct_split.out                | Bin 9519 -> 9558 bytes
 .../distinct_split/disitinct_split.groovy             |   8 +++++++-
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SplitMultiDistinct.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SplitMultiDistinct.java
index 56df1485a83..6adb3270b5b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SplitMultiDistinct.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SplitMultiDistinct.java
@@ -24,9 +24,9 @@ import 
org.apache.doris.nereids.rules.rewrite.SplitMultiDistinct.DistinctSplitCo
 import org.apache.doris.nereids.trees.copier.DeepCopierContext;
 import org.apache.doris.nereids.trees.copier.LogicalPlanDeepCopier;
 import org.apache.doris.nereids.trees.expressions.Alias;
-import org.apache.doris.nereids.trees.expressions.EqualTo;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.NullSafeEqual;
 import org.apache.doris.nereids.trees.expressions.OrderExpression;
 import org.apache.doris.nereids.trees.expressions.Slot;
 import 
org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
@@ -273,7 +273,7 @@ public class SplitMultiDistinct extends 
DefaultPlanRewriter<DistinctSplitContext
             List<Slot> rightSlots = newAggs.get(1).getOutput();
             List<Expression> hashConditions = new ArrayList<>();
             for (int i = 0; i < len; ++i) {
-                hashConditions.add(new EqualTo(leftSlots.get(i), 
rightSlots.get(i)));
+                hashConditions.add(new NullSafeEqual(leftSlots.get(i), 
rightSlots.get(i)));
             }
             join = new LogicalJoin<>(JoinType.INNER_JOIN, hashConditions, 
newAggs.get(0), newAggs.get(1), null);
             for (int j = 2; j < newAggs.size(); ++j) {
@@ -281,7 +281,7 @@ public class SplitMultiDistinct extends 
DefaultPlanRewriter<DistinctSplitContext
                 List<Slot> belowRightSlots = newAggs.get(j).getOutput();
                 List<Expression> aboveHashConditions = new ArrayList<>();
                 for (int i = 0; i < len; ++i) {
-                    aboveHashConditions.add(new EqualTo(belowJoinSlots.get(i), 
belowRightSlots.get(i)));
+                    aboveHashConditions.add(new 
NullSafeEqual(belowJoinSlots.get(i), belowRightSlots.get(i)));
                 }
                 join = new LogicalJoin<>(JoinType.INNER_JOIN, 
aboveHashConditions, join, newAggs.get(j), null);
             }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/SplitMultiDistinctTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/SplitMultiDistinctTest.java
index 074135695a1..ebc6331506a 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/SplitMultiDistinctTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/SplitMultiDistinctTest.java
@@ -17,6 +17,8 @@
 
 package org.apache.doris.nereids.rules.rewrite;
 
+import org.apache.doris.nereids.trees.expressions.NullSafeEqual;
+import org.apache.doris.nereids.trees.plans.JoinType;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.util.MatchingUtils;
 import org.apache.doris.nereids.util.MemoPatternMatchSupported;
@@ -180,6 +182,8 @@ public class SplitMultiDistinctTest extends 
TestWithFeService implements MemoPat
                                                                     
physicalHashAggregate(
                                                                             
physicalDistribute(
                                                                                
     physicalHashAggregate(any()))))
+                                                    ).when(join ->
+                                                        join.getJoinType() == 
JoinType.INNER_JOIN && join.getHashJoinConjuncts().get(0) instanceof 
NullSafeEqual
                                                     )
                                             )
                                     )
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 2a1dd6fd9d6..a0aff0a9a19 100644
Binary files 
a/regression-test/data/nereids_rules_p0/distinct_split/disitinct_split.out and 
b/regression-test/data/nereids_rules_p0/distinct_split/disitinct_split.out 
differ
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 02812b269a3..9efe6ce487a 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
@@ -207,4 +207,10 @@ suite("distinct_split") {
         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
+
+    //----------------test null hash join ------------------------
+    sql "drop table if exists test_distinct_multi_null_hash;"
+    sql "create table test_distinct_multi_null_hash(a int, b int, c int, d 
varchar(10), e date) distributed by hash(a) properties('replication_num'='1');"
+    sql "insert into test_distinct_multi_null_hash 
values(1,null,null,null,'2024-12-08');"
+    qt_null_hash "SELECT a, b, count(distinct c,e), count(distinct 
concat(d,e))/count(distinct e) FROM test_distinct_multi_null_hash where e = 
'2024-12-08' GROUP BY a, b;"
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to