You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Viliam Durina (Jira)" <ji...@apache.org> on 2022/08/04 13:35:00 UTC
[jira] [Created] (CALCITE-5228) RexSimplify.simplifyCast throws NumberFormatException
Viliam Durina created CALCITE-5228:
--------------------------------------
Summary: 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
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)