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 2633a23388eb94..2be8a3c2c0cb42 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 @@ -49,7 +49,9 @@ public Expression withChildren(List children) { @Override public DecimalV3Type getDataTypeForDecimalV3(DecimalV3Type t1, DecimalV3Type t2) { - return (DecimalV3Type) DecimalV3Type.widerDecimalV3Type(t1, t2, false); + DecimalV3Type decimalV3Type = (DecimalV3Type) DecimalV3Type.widerDecimalV3Type(t1, t2, false); + return (DecimalV3Type) DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision() + 1, + decimalV3Type.getScale()); } @Override 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 a7367142ec4e5d..1536d88d0284d9 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 @@ -49,7 +49,9 @@ public Expression withChildren(List children) { @Override public DecimalV3Type getDataTypeForDecimalV3(DecimalV3Type t1, DecimalV3Type t2) { - return (DecimalV3Type) DecimalV3Type.widerDecimalV3Type(t1, t2, false); + DecimalV3Type decimalV3Type = (DecimalV3Type) DecimalV3Type.widerDecimalV3Type(t1, t2, false); + return (DecimalV3Type) DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision() + 1, + decimalV3Type.getScale()); } @Override diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/TypeCoercionUtilsTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/TypeCoercionUtilsTest.java index 0740403373503b..a30d67d4d314e4 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/TypeCoercionUtilsTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/TypeCoercionUtilsTest.java @@ -727,12 +727,12 @@ public void testDecimalArithmetic() { new DecimalV3Literal(new BigDecimal("123.45"))); expression = TypeCoercionUtils.processBinaryArithmetic(add); Assertions.assertEquals(expression.child(0), - new Cast(multiply.child(0), DecimalV3Type.createDecimalV3Type(9, 3))); + new Cast(multiply.child(0), DecimalV3Type.createDecimalV3Type(10, 3))); Subtract sub = new Subtract(new DecimalLiteral(new BigDecimal("987654.321")), new DecimalV3Literal(new BigDecimal("123.45"))); expression = TypeCoercionUtils.processBinaryArithmetic(sub); Assertions.assertEquals(expression.child(0), - new Cast(multiply.child(0), DecimalV3Type.createDecimalV3Type(9, 3))); + new Cast(multiply.child(0), DecimalV3Type.createDecimalV3Type(10, 3))); } }