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

commit f85b04c2c65578e6d142f2f13494bb0e2f728bfa
Author: Nitin-Kashyap <[email protected]>
AuthorDate: Wed Jan 24 07:27:23 2024 +0530

    [fix](datatype) fixed decimal type implicit cast handling in 
BinaryPredicate (#30181)
---
 .../main/java/org/apache/doris/analysis/Expr.java  | 13 +++-
 .../test_predicate_with_implicit_cast.out          | 19 ++++++
 .../test_predicate_with_implicit_cast.groovy       | 71 ++++++++++++++++++++++
 3 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
index 465c2c947c8..c2341b8eead 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
@@ -1674,10 +1674,19 @@ public abstract class Expr extends TreeNode<Expr> 
implements ParseNode, Cloneabl
         Type t2 = getChild(1).getType();
         // add operand casts
         Preconditions.checkState(compatibleType.isValid());
-        if (t1.getPrimitiveType() != compatibleType.getPrimitiveType()) {
+        if (t1.isDecimalV3() || t1.isDecimalV2()) {
+            if (!t1.equals(compatibleType)) {
+                castChild(compatibleType, 0);
+            }
+        } else if (t1.getPrimitiveType() != compatibleType.getPrimitiveType()) 
{
             castChild(compatibleType, 0);
         }
-        if (t2.getPrimitiveType() != compatibleType.getPrimitiveType()) {
+
+        if (t2.isDecimalV3() || t2.isDecimalV2()) {
+            if (!t2.equals(compatibleType)) {
+                castChild(compatibleType, 1);
+            }
+        } else if (t2.getPrimitiveType() != compatibleType.getPrimitiveType()) 
{
             castChild(compatibleType, 1);
         }
         return compatibleType;
diff --git 
a/regression-test/data/datatype_p0/decimalv3/test_predicate_with_implicit_cast.out
 
b/regression-test/data/datatype_p0/decimalv3/test_predicate_with_implicit_cast.out
new file mode 100644
index 00000000000..600f0488fab
--- /dev/null
+++ 
b/regression-test/data/datatype_p0/decimalv3/test_predicate_with_implicit_cast.out
@@ -0,0 +1,19 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !decimalv3_1 --
+5.7    5.70    5.70
+
+-- !decimalv3_2 --
+5.7    5.70    5.70
+
+-- !decimalv3_3 --
+5.7    5.70    5.70
+
+-- !decimalv3_1 --
+5.7    5.70    5.70
+
+-- !decimalv3_2 --
+5.7    5.70    5.70
+
+-- !decimalv3_3 --
+5.7    5.70    5.70
+
diff --git 
a/regression-test/suites/datatype_p0/decimalv3/test_predicate_with_implicit_cast.groovy
 
b/regression-test/suites/datatype_p0/decimalv3/test_predicate_with_implicit_cast.groovy
new file mode 100644
index 00000000000..70cc0f935aa
--- /dev/null
+++ 
b/regression-test/suites/datatype_p0/decimalv3/test_predicate_with_implicit_cast.groovy
@@ -0,0 +1,71 @@
+// 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("test_predicate_with_implicit_cast") {
+    def tableName1 = "test_decimalv3_to_decimalv3_1"
+    def tableName2 = "test_decimalv3_to_decimalv3_2"
+
+    def prepare_test_decimalV3_to_decimalV3 = {
+        sql "drop table if exists ${tableName1};"
+        sql """
+            create table ${tableName1}(
+                a DECIMAL(2, 1), 
+                b DECIMAL(3, 2)
+            ) 
+            ENGINE=OLAP
+            DUPLICATE KEY(a) COMMENT "OLAP"
+            DISTRIBUTED BY HASH(a) BUCKETS auto
+            PROPERTIES ( "replication_num" = "1" );
+        """
+        sql "drop table if exists ${tableName2};"
+        sql """
+            create table ${tableName2}(
+                c DECIMAL(3, 2)
+            ) 
+            ENGINE=OLAP
+            DUPLICATE KEY(c) COMMENT "OLAP"
+            DISTRIBUTED BY HASH(c) BUCKETS auto
+            PROPERTIES ( "replication_num" = "1" );
+        """
+    }
+
+    def q01 = {
+        qt_decimalv3_1 "SELECT * FROM ${tableName1}, ${tableName2} WHERE a=c;"
+        qt_decimalv3_2 "SELECT * FROM ${tableName1}, ${tableName2} WHERE a IN 
(c);"
+        qt_decimalv3_3 "SELECT * FROM ${tableName1}, ${tableName2} WHERE 
cast(a as DecimalV3(3,2))=c;"
+    }
+
+    prepare_test_decimalV3_to_decimalV3()
+
+    sql """
+        insert into ${tableName1} values (5.7, 5.70);
+    """
+
+    sql """
+        insert into ${tableName2} values(5.70);
+    """
+
+    sql """set enable_fallback_to_original_planner=false;"""
+
+    // with nereids planner
+    q01()
+
+    sql """set enable_nereids_planner=false;"""
+
+    // with legacy planner
+    q01()
+}
\ No newline at end of file


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

Reply via email to