Skip to content

Commit f499ddd

Browse files
nokiaMSgithubgxll
authored andcommitted
[fix][runtime] Make BIGINT OPs to be compatible with mysql.
1 parent e4f0c71 commit f499ddd

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

runtime/src/main/java/io/dingodb/expr/runtime/op/arithmetic/AddOpFactory.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,11 @@ protected Object evalNonNullValue(@NonNull Object value0, @NonNull Object value1
225225
}
226226
} else if (value0 instanceof Long) {
227227
if (value1 instanceof Long) {
228-
return (Long)value0 + ((Long) value1);
228+
try {
229+
return Math.addExact((Long) value0, (Long) value1);
230+
} catch (ArithmeticException e) {
231+
throw new RuntimeException("BIGINT is out of range.");
232+
}
229233
} else if (value1 instanceof Integer) {
230234
return (long)value0 + ((Integer) value1).longValue();
231235
} else if (value1 instanceof Double) {

runtime/src/main/java/io/dingodb/expr/runtime/op/arithmetic/MulOp.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ static int mul(int value0, int value1) {
3232
}
3333

3434
static long mul(long value0, long value1) {
35-
return value0 * value1;
35+
try {
36+
return Math.multiplyExact(value0, value1);
37+
} catch (ArithmeticException e) {
38+
throw new RuntimeException("BIGINT value is out of range.");
39+
}
3640
}
3741

3842
static float mul(float value0, float value1) {

runtime/src/main/java/io/dingodb/expr/runtime/op/arithmetic/SubOp.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ static int sub(int value0, int value1) {
3232
}
3333

3434
static long sub(long value0, long value1) {
35-
return value0 - value1;
35+
try {
36+
return Math.subtractExact(value0, value1);
37+
} catch (ArithmeticException e) {
38+
throw new RuntimeException("BIGINT value is out of range.");
39+
}
3640
}
3741

3842
static float sub(float value0, float value1) {

0 commit comments

Comments
 (0)