[
https://issues.apache.org/jira/browse/CALCITE-3484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16976865#comment-16976865
]
Julian Hyde edited comment on CALCITE-3484 at 11/18/19 10:18 PM:
-----------------------------------------------------------------
Without spending several hours figuring it out, I don't know. That CASE
condition is incredibly complex.
Have you tried using {{SqlToRelConverter}} with {{Config.isExpand()}} false?
Then it will create {{RexSubQuery}} expressions that can be handled by
{{SubQueryRemoveRule}}.
was (Author: julianhyde):
Without spending several hours figuring it out, I don't know. That CASE
condition is incredibly complex.
Have you tried using {{SqlToRelConverter}} with {{Config.isExpand()}} false?
Then it will create {RexSubQuery}} expressions that can be handled by
{{SubQueryRemoveRule}}.
> SqlToRelConverter: ClassCastException when processing a query with ANY and
> UNNEST
> ---------------------------------------------------------------------------------
>
> Key: CALCITE-3484
> URL: https://issues.apache.org/jira/browse/CALCITE-3484
> Project: Calcite
> Issue Type: Bug
> Affects Versions: 1.21.0
> Reporter: Ruben Q L
> Priority: Major
>
> The problem can be reproduced by adding the following test to
> SqlToRelConverterTest.java:
> {code}
> @Test public void testEqAnyUnnest() {
> final String sql = "select d.deptno from dept_nested d WHERE 'john' = ANY
> (SELECT e.ename from UNNEST(d.employees) e)";
> sql(sql).ok();
> }
> {code}
> Which throws the following exception:
> {code}
> java.lang.ClassCastException: org.apache.calcite.rel.logical.LogicalCorrelate
> cannot be cast to org.apache.calcite.rel.core.Join
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.translateIn(SqlToRelConverter.java:1285)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.substituteSubQuery(SqlToRelConverter.java:1157)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.replaceSubQueries(SqlToRelConverter.java:1013)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertWhere(SqlToRelConverter.java:979)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:648)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:626)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:3180)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:562)
> at
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:626)
> at
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.assertConvertsTo(SqlToRelTestBase.java:745)
> at
> org.apache.calcite.test.SqlToRelConverterTest$Sql.convertsTo(SqlToRelConverterTest.java:3664)
> at
> org.apache.calcite.test.SqlToRelConverterTest$Sql.ok(SqlToRelConverterTest.java:3656)
> at
> org.apache.calcite.test.SqlToRelConverterTest.testEqAnyUnnest(SqlToRelConverterTest.java:1266)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
> at
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
> at
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
> at
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
> at
> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
> {code}
> Note that the following "similar" queries are correctly converted:
> {code}
> @Test public void testUnnestEq() {
> final String sql = "select d.deptno from dept_nested d,
> UNNEST(d.employees) e WHERE e.ename = 'john'";
> sql(sql).ok();
> }
> @Test public void testInUnnest() {
> final String sql = "select d.deptno from dept_nested d WHERE 'john' IN
> (SELECT e.ename from UNNEST(d.employees) e)";
> sql(sql).ok();
> }
> @Test public void testExistsUnnest() {
> final String sql = "select d.deptno from dept_nested d WHERE EXISTS
> (SELECT 1 from UNNEST(d.employees) e WHERE e.ename = 'john')";
> sql(sql).ok();
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)