Skip to content

Commit 13668a6

Browse files
wt0530githubgxll
authored andcommitted
[fix][runtime] Fixed the incorrect result when the abs function takes a value of -2^31 or -2^63
1 parent bee98ed commit 13668a6

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

runtime/src/main/java/io/dingodb/expr/runtime/op/mathematical/AbsCheckFun.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ abstract class AbsCheckFun extends UnaryNumericOp {
3030

3131
private static final long serialVersionUID = 6834907753646404442L;
3232

33-
static int abs(int num) {
33+
static Object abs(int num) {
3434
if (num == Integer.MIN_VALUE) {
35-
throw new ExprEvaluatingException(ExceptionUtils.exceedsIntRange());
35+
return Math.abs(Long.parseLong(String.valueOf(num)));
36+
//throw new ExprEvaluatingException(ExceptionUtils.exceedsIntRange());
3637
}
3738
return Math.abs(num);
3839
}

test/src/test/java/io/dingodb/expr/test/cases/EvalExceptionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
4949
arguments(op(TO_LONG_C, BigDecimal.valueOf(Long.MAX_VALUE).add(BigDecimal.ONE)), CastingException.class),
5050
arguments(op(TO_LONG_C, BigDecimal.valueOf(Long.MIN_VALUE).subtract(BigDecimal.ONE)),
5151
CastingException.class),
52-
arguments(op(ABS_C, Integer.MIN_VALUE), ExprEvaluatingException.class),
52+
/*arguments(op(ABS_C, Integer.MIN_VALUE), ExprEvaluatingException.class),*/
5353
arguments(op(ABS_C, Long.MIN_VALUE), ExprEvaluatingException.class)
5454
);
5555
}

0 commit comments

Comments
 (0)