[fix](Nereids) simplify airthmetic should not change return type (#31237)
This commit is contained in:
@ -25,6 +25,7 @@ import org.apache.doris.nereids.trees.expressions.Divide;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
import org.apache.doris.nereids.trees.expressions.Multiply;
|
||||
import org.apache.doris.nereids.trees.expressions.Subtract;
|
||||
import org.apache.doris.nereids.util.TypeCoercionUtils;
|
||||
import org.apache.doris.nereids.util.TypeUtils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@ -119,7 +120,7 @@ public class SimplifyArithmeticRule extends AbstractExpressionRewriteRule {
|
||||
: Operand.of(true, getAddOrMultiply(isAddOrSub, x, y)));
|
||||
|
||||
if (result.isPresent()) {
|
||||
return result.get().expression;
|
||||
return TypeCoercionUtils.castIfNotSameType(result.get().expression, arithmetic.getDataType());
|
||||
} else {
|
||||
return arithmetic;
|
||||
}
|
||||
|
||||
@ -161,25 +161,25 @@ public class NumericArithmetic {
|
||||
return new LargeIntLiteral(result);
|
||||
}
|
||||
|
||||
@ExecFunction(name = "add", argTypes = {"LARGEINT", "TINYINT"}, returnType = "BIGINT")
|
||||
@ExecFunction(name = "add", argTypes = {"LARGEINT", "TINYINT"}, returnType = "LARGEINT")
|
||||
public static Expression addLargeIntTinyInt(LargeIntLiteral first, TinyIntLiteral second) {
|
||||
BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString()));
|
||||
return new LargeIntLiteral(result);
|
||||
}
|
||||
|
||||
@ExecFunction(name = "add", argTypes = {"LARGEINT", "SMALLINT"}, returnType = "BIGINT")
|
||||
@ExecFunction(name = "add", argTypes = {"LARGEINT", "SMALLINT"}, returnType = "LARGEINT")
|
||||
public static Expression addLargeIntSmallInt(LargeIntLiteral first, SmallIntLiteral second) {
|
||||
BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString()));
|
||||
return new LargeIntLiteral(result);
|
||||
}
|
||||
|
||||
@ExecFunction(name = "add", argTypes = {"LARGEINT", "INT"}, returnType = "BIGINT")
|
||||
@ExecFunction(name = "add", argTypes = {"LARGEINT", "INT"}, returnType = "LARGEINT")
|
||||
public static Expression addLargeIntInt(LargeIntLiteral first, IntegerLiteral second) {
|
||||
BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString()));
|
||||
return new LargeIntLiteral(result);
|
||||
}
|
||||
|
||||
@ExecFunction(name = "add", argTypes = {"LARGEINT", "BIGINT"}, returnType = "BIGINT")
|
||||
@ExecFunction(name = "add", argTypes = {"LARGEINT", "BIGINT"}, returnType = "LARGEINT")
|
||||
public static Expression addLargeIntBigInt(LargeIntLiteral first, BigIntLiteral second) {
|
||||
BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString()));
|
||||
return new LargeIntLiteral(result);
|
||||
|
||||
Reference in New Issue
Block a user