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 c863f06194..4bf92c6c4b 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 @@ -512,8 +512,16 @@ public class ArithmeticExpr extends Expr { } castChild(ScalarType.createDecimalV3Type(precision, targetScale), 0); } else if (op == Operator.MOD) { - castChild(type, 0); - castChild(type, 1); + // TODO use max int part + max scale of two operands as result type + // because BE require the result and operands types are the exact the same decimalv3 type + precision = Math.max(widthOfIntPart1, widthOfIntPart2) + scale; + if (precision > ScalarType.MAX_DECIMAL128_PRECISION) { + type = castBinaryOp(Type.DOUBLE); + } else { + type = ScalarType.createDecimalV3Type(precision, scale); + castChild(type, 0); + castChild(type, 1); + } } break; case INT_DIVIDE: diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Mod.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Mod.java index f7e1443f39..8154d4afbc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Mod.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Mod.java @@ -44,8 +44,10 @@ public class Mod extends BinaryArithmetic implements AlwaysNullable { @Override public DecimalV3Type getDataTypeForDecimalV3(DecimalV3Type t1, DecimalV3Type t2) { + // TODO use max int part + max scale of two operands as result type + // because BE require the result and operands types are the exact the same decimalv3 type int scale = Math.max(t1.getScale(), t2.getScale()); - int precision = t2.getRange() + scale; + int precision = Math.max(t1.getRange(), t2.getRange()) + scale; return DecimalV3Type.createDecimalV3Type(precision, scale); }