[
https://issues.apache.org/jira/browse/CALCITE-5843?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Mihai Budiu updated CALCITE-5843:
---------------------------------
Summary: Constant expression with nested casts causes a compiler crash
(was: Legal constant SQL expression with cast causes a parse error)
> Constant expression with nested casts causes a compiler crash
> -------------------------------------------------------------
>
> Key: CALCITE-5843
> URL: https://issues.apache.org/jira/browse/CALCITE-5843
> Project: Calcite
> Issue Type: Bug
> Components: linq4j
> Affects Versions: 1.34.0
> Reporter: Mihai Budiu
> Priority: Minor
> Labels: pull-request-available
>
> This program fails at compilation time:
> {code:sql}
> SELECT CAST(CAST('32767.4' AS FLOAT) AS SMALLINT)
> {code}
> This happens in linq4j in Expressions.constant:
> {code:java}
> if ((clazz != Float.class && clazz != Double.class || !(value instanceof
> BigDecimal)) && !clazz.isInstance(value)) {
> String stringValue = String.valueOf(value);
> if (type == BigDecimal.class) {
> value = new BigDecimal(stringValue);
> }
> if (type == BigInteger.class) {
> value = new BigInteger(stringValue);
> }
> if (primitive != null) {
> value = primitive.parse(stringValue); // << error
> happens here
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)