[
https://issues.apache.org/jira/browse/CALCITE-5228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17576202#comment-17576202
]
Benchao Li commented on CALCITE-5228:
-------------------------------------
[~vilo] Thanks for reporting this. It seems it's related to CALCITE-4861.
However, I think the exception is expected. In CALCITE-4861, we decided to
leave the runtime behavior of casting to future work.
> RexSimplify.simplifyCast throws NumberFormatException
> -----------------------------------------------------
>
> Key: CALCITE-5228
> URL: https://issues.apache.org/jira/browse/CALCITE-5228
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.31
> Reporter: Viliam Durina
> Priority: Major
>
> When simplifying the following expression:
> {code:java}
> CAST(42.1:REAL):INTEGER NOT NULL
> {code}
> The simplifier throws:
> {code:java}
> java.lang.NumberFormatException: For input string: "42.1"
> at
> java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
> at java.base/java.lang.Integer.parseInt(Integer.java:668)
> at java.base/java.lang.Integer.valueOf(Integer.java:999)
> at org.apache.calcite.linq4j.tree.Primitive.parse(Primitive.java:953)
> at
> org.apache.calcite.linq4j.tree.Expressions.constant(Expressions.java:572)
> at
> org.apache.calcite.linq4j.tree.OptimizeShuttle.visit(OptimizeShuttle.java:291)
> at
> org.apache.calcite.linq4j.tree.UnaryExpression.accept(UnaryExpression.java:39)
> at
> org.apache.calcite.linq4j.tree.TernaryExpression.accept(TernaryExpression.java:47)
> at
> org.apache.calcite.linq4j.tree.Expressions.acceptExpressions(Expressions.java:3205)
> at
> org.apache.calcite.linq4j.tree.NewArrayExpression.accept(NewArrayExpression.java:49)
> at
> org.apache.calcite.linq4j.tree.GotoStatement.accept(GotoStatement.java:64)
> at
> org.apache.calcite.linq4j.tree.BlockBuilder.optimize(BlockBuilder.java:454)
> at
> org.apache.calcite.linq4j.tree.BlockBuilder.toBlock(BlockBuilder.java:338)
> at
> org.apache.calcite.rex.RexExecutorImpl.compile(RexExecutorImpl.java:102)
> at
> org.apache.calcite.rex.RexExecutorImpl.compile(RexExecutorImpl.java:68)
> at
> org.apache.calcite.rex.RexExecutorImpl.reduce(RexExecutorImpl.java:132)
> at
> org.apache.calcite.rex.RexSimplify.simplifyCast(RexSimplify.java:2216)
> at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:289)
> at
> org.apache.calcite.rex.RexSimplify.simplifyUnknownAs(RexSimplify.java:248)
> at
> org.apache.calcite.rex.RexSimplify.simplifyPreservingType(RexSimplify.java:187)
> at
> org.apache.calcite.rex.RexSimplify.simplifyPreservingType(RexSimplify.java:182)
> {code}
> The expression is a {{RexCall}} having a {{RexLiteral}} operand. The
> literal's type is REAL, the CAST casts to INTEGER. The issue didn't reproduce
> in 1.30.
> To reproduce, add the following test to {{{}ToLogicalConverterTest{}}} and
> run it:
> {code:java}
> @Test void test() {
> verify(rel("insert into \"employee\" values(" +
> "cast(42.1 as real), 'a', 'b', 'c', null, null, 1, 1, date'2022-2-2',
> null, null, 123, null, 'foo', 'single', 'non-human', null)"), "foo", "foo");
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)