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

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

commit bb4a28d8065feb10a549e7055d791d6917257c97
Author: Gabriel <[email protected]>
AuthorDate: Mon Apr 17 16:43:36 2023 +0800

    [Bug](DECIMAL) Fix bug for arithmatic expr DECIMALV2 / DECIMALV3 (#18723)
---
 .../org/apache/doris/analysis/ArithmeticExpr.java  |  2 +-
 .../decimalv3/test_arithmetic_expressions.out      |  6 ++++++
 .../decimalv3/test_arithmetic_expressions.groovy   | 22 ++++++++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java
index 152df98ae1..0efc993d1e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java
@@ -566,7 +566,7 @@ public class ArithmeticExpr extends Expr {
                     if (((ScalarType) type).getScalarScale() != ((ScalarType) 
children.get(1).type).getScalarScale()) {
                         castChild(type, 1);
                     }
-                } else if (op == Operator.DIVIDE && (t2Scale != 0) && 
t1.isDecimalV3()) {
+                } else if (op == Operator.DIVIDE && (t2Scale != 0) && 
t1TargetType.isDecimalV3()) {
                     int targetScale = t1Scale + t2Scale;
                     if (precision < targetScale) {
                         type = castBinaryOp(Type.DOUBLE);
diff --git 
a/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out 
b/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out
index 085b844d7c..7f29407e10 100644
--- a/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out
+++ b/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out
@@ -47,3 +47,9 @@
 -- !select --
 10999999.989
 
+-- !select --
+1      629.028702933   629.028702933
+2      722.810212429   722.810212429
+3      724.291976000   724.291976000
+4      688.890183155   688.890183155
+
diff --git 
a/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy
 
b/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy
index 284cf482e4..b077e4c362 100644
--- 
a/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy
+++ 
b/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy
@@ -65,4 +65,26 @@ suite("test_arithmetic_expressions") {
     qt_select "select (a + b + c) / d from ${table1};"
     qt_select "select a + b + c + d + e + f + g + h + i + j + k from 
${table1};"
     sql "drop table if exists ${table1}"
+
+    def table2 = "test_arithmetic_expressions"
+
+    sql "drop table if exists ${table2}"
+    sql """ create table ${table2} (
+            id smallint,
+            fz decimal(27,9),
+            fzv3 decimalv3(27,9),
+            fm decimalv3(38,10))
+            DISTRIBUTED BY HASH(`id`) BUCKETS auto
+            PROPERTIES
+            (
+                "replication_num" = "1"
+            ); """
+
+    sql """ insert into ${table2} values 
(1,92594283.129196000,92594283.129196000,147202.0000000000); """
+    sql """ insert into ${table2} values 
(2,107684988.257976000,107684988.257976000,148981.0000000000); """
+    sql """ insert into ${table2} values 
(3,76891560.464178000,76891560.464178000,106161.0000000000); """
+    sql """ insert into ${table2} values 
(4,277170831.851350000,277170831.851350000,402344.0000000000); """
+
+    qt_select """ select id, fz/fm as dec,fzv3/fm as decv3 from ${table2} 
ORDER BY id; """
+    sql "drop table if exists ${table2}"
 }


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

Reply via email to