[branch-2.1](function) fix nereids fold constant wrong result of abs (#37065) (#37108)

pick https://github.com/apache/doris/pull/37065
This commit is contained in:
zclllyybb
2024-07-03 11:58:06 +08:00
committed by GitHub
parent fb642d0227
commit 5969d6521f
2 changed files with 68 additions and 4 deletions

View File

@ -47,22 +47,22 @@ public class ExecutableFunctions {
*/
@ExecFunction(name = "abs", argTypes = {"TINYINT"}, returnType = "SMALLINT")
public static Expression abs(TinyIntLiteral literal) {
return new SmallIntLiteral((byte) Math.abs(literal.getValue()));
return new SmallIntLiteral((short) Math.abs(literal.getValue()));
}
@ExecFunction(name = "abs", argTypes = {"SMALLINT"}, returnType = "INT")
public static Expression abs(SmallIntLiteral literal) {
return new IntegerLiteral((short) Math.abs(literal.getValue()));
return new IntegerLiteral(Math.abs(literal.getValue()));
}
@ExecFunction(name = "abs", argTypes = {"INT"}, returnType = "BIGINT")
public static Expression abs(IntegerLiteral literal) {
return new BigIntLiteral(Math.abs(literal.getValue()));
return new BigIntLiteral(Math.abs((long) literal.getValue()));
}
@ExecFunction(name = "abs", argTypes = {"BIGINT"}, returnType = "LARGEINT")
public static Expression abs(BigIntLiteral literal) {
return new LargeIntLiteral(new BigInteger(Long.toString(Math.abs(literal.getValue()))));
return new LargeIntLiteral(BigInteger.valueOf(literal.getValue()).abs());
}
@ExecFunction(name = "abs", argTypes = {"LARGEINT"}, returnType = "LARGEINT")