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
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 3be12f78501 [fix](Nereids) result type of add precision is 1 more than
expected (#27136) (#27426)
3be12f78501 is described below
commit 3be12f78501d9121e845a32ac54b92abaa91c75d
Author: morrySnow <[email protected]>
AuthorDate: Thu Nov 23 12:34:36 2023 +0800
[fix](Nereids) result type of add precision is 1 more than expected
(#27136) (#27426)
---
.../java/org/apache/doris/nereids/trees/expressions/Add.java | 2 +-
.../doris/nereids/trees/expressions/BinaryArithmetic.java | 6 +++++-
.../org/apache/doris/nereids/trees/expressions/Subtract.java | 2 +-
regression-test/suites/nereids_arith_p0/decimal.groovy | 12 ++++++++++++
4 files changed, 19 insertions(+), 3 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Add.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Add.java
index 2be8a3c2c0c..bf19192ff5c 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Add.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Add.java
@@ -50,7 +50,7 @@ public class Add extends BinaryArithmetic implements
CheckOverflowNullable {
@Override
public DecimalV3Type getDataTypeForDecimalV3(DecimalV3Type t1,
DecimalV3Type t2) {
DecimalV3Type decimalV3Type = (DecimalV3Type)
DecimalV3Type.widerDecimalV3Type(t1, t2, false);
- return (DecimalV3Type)
DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision() + 1,
+ return DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision()
+ 1,
decimalV3Type.getScale());
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryArithmetic.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryArithmetic.java
index 501af7470cb..61440f4147d 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryArithmetic.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryArithmetic.java
@@ -61,7 +61,11 @@ public abstract class BinaryArithmetic extends
BinaryOperator implements Propaga
return getDataTypeForDecimalV2((DecimalV2Type) t1, (DecimalV2Type)
t2);
}
if (t1.isDecimalV3Type() && t2.isDecimalV3Type()) {
- return getDataTypeForDecimalV3((DecimalV3Type) t1, (DecimalV3Type)
t2);
+ if (this instanceof Add || this instanceof Subtract || this
instanceof Mod) {
+ return t1;
+ } else {
+ return getDataTypeForDecimalV3((DecimalV3Type) t1,
(DecimalV3Type) t2);
+ }
}
return getDataTypeForOthers(t1, t2);
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Subtract.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Subtract.java
index 1536d88d028..0b38694769b 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Subtract.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Subtract.java
@@ -50,7 +50,7 @@ public class Subtract extends BinaryArithmetic implements
CheckOverflowNullable
@Override
public DecimalV3Type getDataTypeForDecimalV3(DecimalV3Type t1,
DecimalV3Type t2) {
DecimalV3Type decimalV3Type = (DecimalV3Type)
DecimalV3Type.widerDecimalV3Type(t1, t2, false);
- return (DecimalV3Type)
DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision() + 1,
+ return DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision()
+ 1,
decimalV3Type.getScale());
}
diff --git a/regression-test/suites/nereids_arith_p0/decimal.groovy
b/regression-test/suites/nereids_arith_p0/decimal.groovy
index a7f18705f21..12665ce86da 100644
--- a/regression-test/suites/nereids_arith_p0/decimal.groovy
+++ b/regression-test/suites/nereids_arith_p0/decimal.groovy
@@ -2299,4 +2299,16 @@ suite('nereids_arith_p0_decimal') {
// select id, BITAND(kdcml128v3, kbool), BITOR(kdcml128v3, kbool),
BITXOR(kdcml128v3, kbool) from expr_test order by id"""
// qt_sql_test_Decimal128V3_Boolean_notn_4 """
// select id, BITAND(kdcml128v3, kbool), BITOR(kdcml128v3, kbool),
BITXOR(kdcml128v3, kbool) from expr_test_not_nullable order by id"""
+
+
+ // decimal add precision
+ sql """drop table if exists test_arithmetic_expressions"""
+ sql """
+ CREATE TABLE IF NOT EXISTS test_arithmetic_expressions (
+ `a` DECIMALV3(9, 3) NOT NULL,
+ `b` DECIMALV3(9, 3) NOT NULL
+ ) DISTRIBUTED BY HASH(a) PROPERTIES("replication_num" = "1");
+ """
+ sql "select a + b from test_arithmetic_expressions"
+ sql """drop table if exists test_arithmetic_expressions"""
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]