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

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


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 2576d6be033 branch-3.0: [Bug](intersect) fix wrong result of intersect 
with null literal #50951 (#51178)
2576d6be033 is described below

commit 2576d6be0333d548ae3512711cf53d689c09deee
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri May 23 20:19:41 2025 +0800

    branch-3.0: [Bug](intersect) fix wrong result of intersect with null 
literal #50951 (#51178)
    
    Cherry-picked from #50951
    
    Co-authored-by: Pxl <x...@selectdb.com>
---
 .../nereids/rules/rewrite/PullUpPredicates.java    |  14 +++++-
 .../infer_predicate/pull_up_predicate_literal.out  | Bin 86132 -> 110312 bytes
 .../set_operations/set_with_null/set_with_null.out | Bin 0 -> 123 bytes
 .../set_with_null/set_with_null.groovy             |  55 +++++++++++++++++++++
 4 files changed, 67 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpPredicates.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpPredicates.java
index 8ced9374bc9..a2d820a9ccd 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpPredicates.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpPredicates.java
@@ -21,6 +21,7 @@ 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.InPredicate;
+import org.apache.doris.nereids.trees.expressions.IsNull;
 import org.apache.doris.nereids.trees.expressions.NamedExpression;
 import org.apache.doris.nereids.trees.expressions.Slot;
 import 
org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
@@ -134,7 +135,7 @@ public class PullUpPredicates extends 
PlanVisitor<ImmutableSet<Expression>, Void
             Set<Expression> predicates = new LinkedHashSet<>();
             for (NamedExpression expr : r.getProjects()) {
                 if (expr instanceof Alias && expr.child(0) instanceof Literal) 
{
-                    predicates.add(new EqualTo(expr.toSlot(), expr.child(0)));
+                    predicates.add(generateEqual(expr));
                 }
             }
             return ImmutableSet.copyOf(predicates);
@@ -262,7 +263,7 @@ public class PullUpPredicates extends 
PlanVisitor<ImmutableSet<Expression>, Void
             }
             for (NamedExpression expr : project.getProjects()) {
                 if (expr instanceof Alias && expr.child(0) instanceof Literal) 
{
-                    allPredicates.add(new EqualTo(expr.toSlot(), 
expr.child(0)));
+                    allPredicates.add(generateEqual(expr));
                 }
             }
             return getAvailableExpressions(allPredicates, project);
@@ -379,4 +380,13 @@ public class PullUpPredicates extends 
PlanVisitor<ImmutableSet<Expression>, Void
         }
         return ImmutableSet.copyOf(filtersFromConstExprs);
     }
+
+    private Expression generateEqual(NamedExpression expr) {
+        // IsNull have better performance and compatibility than 
NullSafeEqualTo
+        if (expr.child(0) instanceof NullLiteral) {
+            return new IsNull(expr.toSlot());
+        } else {
+            return new EqualTo(expr.toSlot(), expr.child(0));
+        }
+    }
 }
diff --git 
a/regression-test/data/nereids_rules_p0/infer_predicate/pull_up_predicate_literal.out
 
b/regression-test/data/nereids_rules_p0/infer_predicate/pull_up_predicate_literal.out
index 08dee815c3f..88d7fa790d9 100644
Binary files 
a/regression-test/data/nereids_rules_p0/infer_predicate/pull_up_predicate_literal.out
 and 
b/regression-test/data/nereids_rules_p0/infer_predicate/pull_up_predicate_literal.out
 differ
diff --git 
a/regression-test/data/query_p0/set_operations/set_with_null/set_with_null.out 
b/regression-test/data/query_p0/set_operations/set_with_null/set_with_null.out
new file mode 100644
index 00000000000..82bb49e972d
Binary files /dev/null and 
b/regression-test/data/query_p0/set_operations/set_with_null/set_with_null.out 
differ
diff --git 
a/regression-test/suites/query_p0/set_operations/set_with_null/set_with_null.groovy
 
b/regression-test/suites/query_p0/set_operations/set_with_null/set_with_null.groovy
new file mode 100644
index 00000000000..06a57e1c1b1
--- /dev/null
+++ 
b/regression-test/suites/query_p0/set_operations/set_with_null/set_with_null.groovy
@@ -0,0 +1,55 @@
+// 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.
+
+// The cases is copied from https://github.com/trinodb/trino/tree/master
+// 
/testing/trino-product-tests/src/main/resources/sql-tests/testcases/aggregate
+// and modified by Doris.
+
+suite("set_with_null") {
+    sql " drop table if exists d_table;"
+    sql """
+    create table d_table (
+        k1 int null
+    )
+    duplicate key (k1)
+    distributed BY hash(k1) buckets 3
+    properties("replication_num" = "1");
+    """
+   sql "insert into d_table values (null);"
+
+   qt_test """
+    (
+        select k1
+        from d_table
+    )
+    intersect
+    (
+        select null
+    )
+   """
+
+    qt_test """
+    (
+        select k1
+        from d_table
+    )
+    except
+    (
+        select null
+    )
+   """
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to