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

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

commit 1f1cc3b04d13c01d92edb53178a53dab4b19057e
Author: starocean999 <[email protected]>
AuthorDate: Fri Jul 21 23:40:08 2023 +0800

    [fix](nereids)PredicatePropagation only support integer types for now 
(#22096)
---
 .../rules/rewrite/PredicatePropagation.java        | 22 ++++++++++------------
 .../infer_predicate/infer_predicate.groovy         |  7 +++++++
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PredicatePropagation.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PredicatePropagation.java
index 9602bb4a56..cc45952817 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PredicatePropagation.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PredicatePropagation.java
@@ -83,14 +83,14 @@ public class PredicatePropagation {
                 return super.visit(cp, context);
             }
 
-            private boolean isOriginDataTypeBigger(DataType originDataType, 
Expression expr) {
+            private boolean isDataTypeValid(DataType originDataType, 
Expression expr) {
                 if ((leftSlotEqualToRightSlot.child(0).getDataType() 
instanceof IntegralType)
                         && (leftSlotEqualToRightSlot.child(1).getDataType() 
instanceof IntegralType)
                                 && (originDataType instanceof IntegralType)) {
                     // infer filter can not be lower than original datatype, 
or dataset would be wrong
-                    if (((IntegralType) originDataType).widerThan(
+                    if (!((IntegralType) originDataType).widerThan(
                             (IntegralType) 
leftSlotEqualToRightSlot.child(0).getDataType())
-                                    || ((IntegralType) 
originDataType).widerThan(
+                                    && !((IntegralType) 
originDataType).widerThan(
                                             (IntegralType) 
leftSlotEqualToRightSlot.child(1).getDataType())) {
                         return true;
                     }
@@ -100,16 +100,14 @@ public class PredicatePropagation {
 
             private Expression replaceSlot(Expression expr, DataType 
originDataType) {
                 return expr.rewriteUp(e -> {
-                    if (isOriginDataTypeBigger(originDataType, 
leftSlotEqualToRightSlot)) {
-                        return e;
-                    }
-                    if (ExpressionUtils.isTwoExpressionEqualWithCast(e, 
leftSlotEqualToRightSlot.child(0))) {
-                        return leftSlotEqualToRightSlot.child(1);
-                    } else if (ExpressionUtils.isTwoExpressionEqualWithCast(e, 
leftSlotEqualToRightSlot.child(1))) {
-                        return leftSlotEqualToRightSlot.child(0);
-                    } else {
-                        return e;
+                    if (isDataTypeValid(originDataType, 
leftSlotEqualToRightSlot)) {
+                        if (ExpressionUtils.isTwoExpressionEqualWithCast(e, 
leftSlotEqualToRightSlot.child(0))) {
+                            return leftSlotEqualToRightSlot.child(1);
+                        } else if 
(ExpressionUtils.isTwoExpressionEqualWithCast(e, 
leftSlotEqualToRightSlot.child(1))) {
+                            return leftSlotEqualToRightSlot.child(0);
+                        }
                     }
+                    return e;
                 });
             }
         }, null);
diff --git 
a/regression-test/suites/nereids_p0/infer_predicate/infer_predicate.groovy 
b/regression-test/suites/nereids_p0/infer_predicate/infer_predicate.groovy
index ac46201185..f93de7273b 100644
--- a/regression-test/suites/nereids_p0/infer_predicate/infer_predicate.groovy
+++ b/regression-test/suites/nereids_p0/infer_predicate/infer_predicate.groovy
@@ -26,6 +26,8 @@ suite("test_infer_predicate") {
 
     sql '''create table infer_tb2 (k1 tinyint, k2 smallint, k3 int, k4 bigint, 
k5 largeint, k6 date, k7 datetime, k8 float, k9 double) distributed by hash(k1) 
buckets 3 properties('replication_num' = '1');'''
 
+    sql '''create table infer_tb3 (k1 varchar(100), k2 int) distributed by 
hash(k1) buckets 3 properties('replication_num' = '1');'''
+
     explain {
         sql "select * from infer_tb1 inner join infer_tb2 where infer_tb2.k1 = 
infer_tb1.k2  and infer_tb2.k1 = 1;"
         contains "PREDICATES: k2[#20] = 1"
@@ -40,4 +42,9 @@ suite("test_infer_predicate") {
         sql "select * from infer_tb1 inner join infer_tb2 where 
cast(infer_tb2.k4 as int) = infer_tb1.k2  and infer_tb2.k4 = 1;"
         notContains "PREDICATES: k2[#20] = 1"
     }
+
+    explain {
+        sql "select * from infer_tb1 inner join infer_tb3 where infer_tb3.k1 = 
infer_tb1.k2  and infer_tb3.k1 = '123';"
+        notContains "PREDICATES: k2[#6] = '123'"
+    }
 }


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

Reply via email to