File tree Expand file tree Collapse file tree 4 files changed +6
-7
lines changed
core/src/main/java/org/opensearch/sql/calcite Expand file tree Collapse file tree 4 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -20,14 +20,15 @@ public Object eval(Object... args) {
2020 Number dividend = (Number ) args [0 ];
2121 Number divisor = (Number ) args [1 ];
2222
23- if (Math . abs ( divisor .doubleValue ()) < MathUtils . EPSILON ) {
23+ if (divisor .doubleValue () == 0 ) {
2424 return null ;
2525 }
2626
27- double result = dividend .doubleValue () / divisor .doubleValue ();
2827 if (MathUtils .isIntegral (dividend ) && MathUtils .isIntegral (divisor )) {
29- return MathUtils .coerceToWidestIntegralType (dividend , divisor , (long ) result );
28+ long result = dividend .longValue () / divisor .longValue ();
29+ return MathUtils .coerceToWidestIntegralType (dividend , divisor , result );
3030 }
31+ double result = dividend .doubleValue () / divisor .doubleValue ();
3132 return MathUtils .coerceToWidestFloatingType (dividend , divisor , result );
3233 }
3334}
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ public Object eval(Object... args) {
3333 arg0 .getClass ().getSimpleName (), arg1 .getClass ().getSimpleName ()));
3434 }
3535
36- if (Math . abs ( num1 .doubleValue ()) < MathUtils . EPSILON ) {
36+ if (num1 .doubleValue () == 0 ) {
3737 return null ;
3838 }
3939
Original file line number Diff line number Diff line change 66package org .opensearch .sql .calcite .utils ;
77
88public class MathUtils {
9- public static final double EPSILON = 0.0000001 ;
10-
119 public static boolean isIntegral (Number n ) {
1210 return n instanceof Byte || n instanceof Short || n instanceof Integer || n instanceof Long ;
1311 }
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ Arithmetic expression is an expression formed by numeric literals and binary ari
28281. ``+ ``: Add.
29292. ``- ``: Subtract.
30303. ``* ``: Multiply.
31- 4. ``/ ``: Divide. For integers, the result is an integer with fractional part discarded.
31+ 4. ``/ ``: Divide. For integers, the result is an integer with fractional part discarded. Returns NULL when dividing by zero.
32325. ``% ``: Modulo. This can be used with integers only with remainder of the division as result.
3333
3434Precedence
You can’t perform that action at this time.
0 commit comments