You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Grzegorz Gierlach (Jira)" <ji...@apache.org> on 2021/03/10 14:44:00 UTC

[jira] [Created] (CALCITE-4532) Rex simplification fails with an exception on nested CASTs with ANY

Grzegorz Gierlach created CALCITE-4532:
------------------------------------------

             Summary: Rex simplification fails with an exception on nested CASTs with ANY
                 Key: CALCITE-4532
                 URL: https://issues.apache.org/jira/browse/CALCITE-4532
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.24.0
            Reporter: Grzegorz Gierlach


{code:java}
@Test public void testNestedBigInt() {
  CalciteAssert.AssertThat assertThat = CalciteAssert.that();
  String query = "SELECT CAST(CAST(4200000000 AS BIGINT) AS ANY) FROM (VALUES(1))";
  assertThat.query(query).returns("EXPR$0=4200000000\n");
}
{code}
fails with:
{code:java}
Error while executing SQL "SELECT CAST(CAST(4200000000 AS BIGINT) AS ANY) FROM (VALUES(1))": While compiling [CAST(4200000000:BIGINT):ANY NOT NULL]Error while executing SQL "SELECT CAST(CAST(4200000000 AS BIGINT) AS ANY) FROM (VALUES(1))": While compiling [CAST(4200000000:BIGINT):ANY NOT NULL]java.sql.SQLException: Error while executing SQL "SELECT CAST(CAST(4200000000 AS BIGINT) AS ANY) FROM (VALUES(1))": While compiling [CAST(4200000000:BIGINT):ANY NOT NULL] at org.apache.calcite.avatica.Helper.createException(Helper.java:56) at org.apache.calcite.avatica.Helper.createException(Helper.java:41) at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:163) at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227) at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:534) at org.apache.calcite.test.CalciteAssert$AssertQuery.lambda$returns$1(CalciteAssert.java:1535) at org.apache.calcite.test.CalciteAssert$AssertQuery.withConnection(CalciteAssert.java:1474) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1533) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1523) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1486) at org.apache.calcite.test.JdbcTest.testNestedBigInt(JdbcTest.java:7707) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675) at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125) at org.junit.jupiter.engine.extension.TimeoutInvocation.proceed(TimeoutInvocation.java:46) at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:139) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:131) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:81) at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115) at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:171) at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService.invokeAll(ForkJoinPoolHierarchicalTestExecutorService.java:115) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:171) at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService.invokeAll(ForkJoinPoolHierarchicalTestExecutorService.java:115) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:171) at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:189) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183) Suppressed: org.apache.calcite.util.TestUtil$ExtraInformation: With materializationsEnabled=false, limit=0 at org.apache.calcite.util.TestUtil.rethrow(TestUtil.java:324) at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:566) ... 65 moreCaused by: java.lang.RuntimeException: While compiling [CAST(4200000000:BIGINT):ANY NOT NULL] at org.apache.calcite.rex.RexExecutable.compile(RexExecutable.java:72) at org.apache.calcite.rex.RexExecutable.<init>(RexExecutable.java:52) at org.apache.calcite.rex.RexExecutorImpl.reduce(RexExecutorImpl.java:137) at org.apache.calcite.rex.RexSimplify.simplifyCast(RexSimplify.java:2080) at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:287) at org.apache.calcite.rex.RexSimplify.simplifyUnknownAs(RexSimplify.java:246) at org.apache.calcite.rex.RexSimplify.simplifyPreservingType(RexSimplify.java:185) at org.apache.calcite.rex.RexSimplify.simplifyPreservingType(RexSimplify.java:180) at org.apache.calcite.tools.RelBuilder.project_(RelBuilder.java:1560) at org.apache.calcite.tools.RelBuilder.project(RelBuilder.java:1410) at org.apache.calcite.tools.RelBuilder.projectNamed(RelBuilder.java:1701) at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectList(SqlToRelConverter.java:4345) at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:707) at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:664) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:3538) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:589) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:251) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:215) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:647) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:513) at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:483) at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:236) at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:562) at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675) at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156) ... 67 moreCaused by: org.codehaus.commons.compiler.CompileException: Line 3, Column 7: Invalid integer literal "4200000000" at org.codehaus.janino.UnitCompiler.compileException(UnitCompiler.java:12517) at org.codehaus.janino.UnitCompiler.getConstantValue2(UnitCompiler.java:6120) at org.codehaus.janino.UnitCompiler.access$11200(UnitCompiler.java:215) at org.codehaus.janino.UnitCompiler$18.visitIntegerLiteral(UnitCompiler.java:5718) at org.codehaus.janino.Java$IntegerLiteral.accept(Java.java:5453) at org.codehaus.janino.UnitCompiler.getConstantValue(UnitCompiler.java:5689) at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5654) at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5622) at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:5592) at org.codehaus.janino.UnitCompiler.access$9700(UnitCompiler.java:215) at org.codehaus.janino.UnitCompiler$16.visitNewInitializedArray(UnitCompiler.java:4434) at org.codehaus.janino.UnitCompiler$16.visitNewInitializedArray(UnitCompiler.java:4396) at org.codehaus.janino.Java$NewInitializedArray.accept(Java.java:5373) at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4396) at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5662) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2649) at org.codehaus.janino.UnitCompiler.access$2800(UnitCompiler.java:215) at org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1504) at org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1487) at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:3563) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487) at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3388) at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1357) at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1330) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:822) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:432) at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:215) at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:411) at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:406) at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1414) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406) at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:378) at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:237) at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:465) at org.codehaus.janino.ClassBodyEvaluator.compileToClass(ClassBodyEvaluator.java:313) at org.codehaus.janino.ClassBodyEvaluator.cook(ClassBodyEvaluator.java:235) at org.apache.calcite.rex.RexExecutable.compile(RexExecutable.java:63) ... 91 more
{code}
In a similar fashion:
{code:java}
@Test public void testNestedReal() {
  CalciteAssert.AssertThat assertThat = CalciteAssert.that();
  String query = "SELECT CAST(CAST(1.5 AS REAL) AS ANY) FROM (VALUES(1))";
  assertThat.query(query).returns(r -> {
    try {
      r.next();
      assertEquals(1.5F, r.getObject(1));
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  });
}
{code}
fails with:
{code:java}
expected: java.lang.Float@1f11e9ac<1.5> but was: java.lang.Double@2fb3e8aa<1.5>
{code}
The issue might have been introduced with [CALCITE-3224|https://issues.apache.org/jira/browse/CALCITE-3224]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)