Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
Impala 3.0
-
None
-
None
-
ghx-label-3
Description
The NumericLiteral constructor takes a value and a type. The code does not check that the value is within range of the type, allowing nonsensical values:
NumericLiteral n = new NumericLiteral(new BigDecimal("123.45"), ScalarType.createDecimalType(3, 1)); System.out.println(n.getValue().toString()); n = new NumericLiteral(new BigDecimal(Integer.MAX_VALUE), Type.TINYINT); System.out.println(n.getValue().toString());
Prints:
123.45 2147483647
The value 123.45 is not valid for DECIMAL(3,1), nor is 2^31 valid for TINYINT.
According to the SQL-2016 standard, section 4.4:
If an assignment of some number would result in a loss of its most significant digit, an exception condition is raised.
The purpose of the constructor appears to be for "friendly" use where the caller promises not to create incorrect literals. Better would be to enforce this rule.
Attachments
Issue Links
- Is contained by
-
IMPALA-7902 Revise NumericLiteral to avoid analysis, fix multiple issues
- Resolved