mirror of
https://github.com/apache/druid.git
synced 2025-02-06 01:58:20 +00:00
fixes possible data truncation (#11462)
* fixes possible data truncation * fixes possible data truncation * add unit test case to catch the possible data truncation
This commit is contained in:
parent
2a658acad4
commit
ac2b65e837
@ -219,6 +219,9 @@ public interface Function
|
||||
|
||||
protected ExprEval eval(double param)
|
||||
{
|
||||
if (param < Long.MIN_VALUE || param > Long.MAX_VALUE) {
|
||||
throw new IAE("Possible data truncation, param [%f] is out of long value range", param);
|
||||
}
|
||||
return eval((long) param);
|
||||
}
|
||||
|
||||
|
@ -746,6 +746,15 @@ public class FunctionTest extends InitializedNullHandlingTest
|
||||
assertExpr("bitwiseComplement('1')", null);
|
||||
assertExpr("bitwiseComplement(null)", null);
|
||||
|
||||
// data truncation
|
||||
try {
|
||||
assertExpr("bitwiseComplement(461168601842738800000000000000.000000)", null);
|
||||
Assert.fail("Did not throw IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
Assert.assertEquals("Possible data truncation, param [461168601842738800000000000000.000000] is out of long value range", e.getMessage());
|
||||
}
|
||||
|
||||
// doubles are cast
|
||||
assertExpr("bitwiseOr(2.345, 1)", 3L);
|
||||
assertExpr("bitwiseOr(2, 1.3)", 3L);
|
||||
|
Loading…
x
Reference in New Issue
Block a user