[
https://issues.apache.org/jira/browse/CALCITE-6389?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Mihai Budiu resolved CALCITE-6389.
----------------------------------
Fix Version/s: 1.38.0
Resolution: Fixed
Fixed in
https://github.com/apache/calcite/commit/c228804e258f72cd5df0f1f263dcc4f86410d3ff
> RexBuilder.removeCastFromLiteral does not preserve semantics for some types
> of literals
> ---------------------------------------------------------------------------------------
>
> Key: CALCITE-6389
> URL: https://issues.apache.org/jira/browse/CALCITE-6389
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.36.0
> Reporter: Mihai Budiu
> Priority: Minor
> Labels: pull-request-available
> Fix For: 1.38.0
>
>
> 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:
> {code:java}
> if (toType.getSqlTypeName() == SqlTypeName.DECIMAL) {
> final BigDecimal decimalValue = (BigDecimal) value;
> return SqlTypeUtil.isValidDecimalValue(decimalValue, toType);
> }
> {code}
> 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.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)