Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.36.0
Description
This is a bug which I keep fixing as part of several pull requests (not yet merged), so I have decided to make it into a separate issue.
The code in removeCastFromLiteral is supposed to remove casts which are useless.
However, the code is too aggressive for decimal literals. In particular, this fragment:
if (toType.getSqlTypeName() == SqlTypeName.DECIMAL) { final BigDecimal decimalValue = (BigDecimal) value; return SqlTypeUtil.isValidDecimalValue(decimalValue, toType); }
There are at least two bugs here:
- this code removes casts from literals even if they represent types such as interval
- this code does not check properly that the literal can be represented by the type specified by the cast. In particular, the function SqlTypeUtil.isValidDecimalValue does not correctly consider the scale of the resulting type, and may return 'true' even when a number requires rescaling. Removing casts in such a case changes the literal's value. I have submitted a fix for this bug as part of
CALCITE-6322, but that PR hasn't been merged yet.
Attachments
Issue Links
- links to