[ 
https://issues.apache.org/jira/browse/CALCITE-3031?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16829819#comment-16829819
 ] 

Vineet Garg commented on CALCITE-3031:
--------------------------------------

[~hyuan] Support for correlated quantified predicates was on my todo list. I am 
not sure if you are currently working on this one but I have a quick patch to 
fix this at 
[https://github.com/vineetgarg02/calcite/commit/45e15aebd6084883276b833a80c16996e59ab5a4]

This needs more testing of course and is not really ready to be merged. 

Plan generated for this particular query with the patch is as follow. As far as 
I could tell this looks correct to me but I'll appreciate your input.
  
{code:sql}
LogicalProject(EXPR$0=[CAST(OR(AND(IS TRUE(>($0, $10)), IS NOT TRUE(=($11, 
0))), AND(IS TRUE(>($11, $12)), null, IS NOT TRUE(=($11, 0)), IS NOT TRUE(>($0, 
$10))), AND(>($0, $10), IS NOT TRUE(=($11, 0)), IS NOT TRUE(>($0, $10)), IS NOT 
TRUE(>($11, $12))))):BOOLEAN NOT NULL])
  LogicalJoin(condition=[=($2, $9)], joinType=[left])
    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
    LogicalAggregate(group=[{0}], m=[MIN($1)], c=[COUNT()], d=[COUNT($1)])
      LogicalProject(NAME=[$1], DEPTNO=[$0])
        LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
{code}
Please let me know if you haven't started working on this, I'll take this one. 
Otherwise feel free to ignore my patch/comment.

> AssertionError: correlation id $cor0 not found in correlation list []
> ---------------------------------------------------------------------
>
>                 Key: CALCITE-3031
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3031
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Haisheng Yuan
>            Assignee: Haisheng Yuan
>            Priority: Major
>
> Repro:
> {code:java}
> @Test public void testSelectAnyCorrelated() {
>     final String sql = "select empno > any(select deptno from dept where 
> emp.job = dept.name) from emp\n"
>         ;
>     checkSubQuery(sql).withLateDecorrelation(true).check();
>   }
> {code}
> Error:
> {code:java}
> java.lang.AssertionError: correlation id $cor0 not found in correlation list 
> []
>       at org.apache.calcite.util.Litmus$1.fail(Litmus.java:31)
>       at 
> org.apache.calcite.rex.RexChecker.visitCorrelVariable(RexChecker.java:174)
>       at 
> org.apache.calcite.rex.RexChecker.visitCorrelVariable(RexChecker.java:57)
>       at 
> org.apache.calcite.rex.RexCorrelVariable.accept(RexCorrelVariable.java:47)
>       at 
> org.apache.calcite.rex.RexVisitorImpl.visitFieldAccess(RexVisitorImpl.java:98)
>       at 
> org.apache.calcite.rex.RexChecker.visitFieldAccess(RexChecker.java:149)
>       at 
> org.apache.calcite.rex.RexChecker.visitFieldAccess(RexChecker.java:57)
>       at org.apache.calcite.rex.RexFieldAccess.accept(RexFieldAccess.java:81)
>       at org.apache.calcite.rex.RexChecker.visitCall(RexChecker.java:140)
>       at org.apache.calcite.rex.RexChecker.visitCall(RexChecker.java:57)
>       at org.apache.calcite.rex.RexCall.accept(RexCall.java:191)
>       at org.apache.calcite.rel.core.Filter.isValid(Filter.java:120)
>       at 
> org.apache.calcite.test.SqlToRelConverterTest$RelValidityChecker.visit(SqlToRelConverterTest.java:3312)
>       at org.apache.calcite.rel.SingleRel.childrenAccept(SingleRel.java:72)
>       at org.apache.calcite.rel.RelVisitor.visit(RelVisitor.java:44)
> {code}
> The plan after SubQueryRemoveRule is:
> {code:xml}
> LogicalProject(EXPR$0=[CAST(OR(AND(IS TRUE(>($0, $9)), <>($10, 0)), 
> AND(>($10, $11), null, <>($10, 0), IS NOT TRUE(>($0, $9))), AND(>($0, $9), 
> <>($10, 0), IS NOT TRUE(>($0, $9)), <=($10, $11)))):BOOLEAN NOT NULL])
>   LogicalJoin(condition=[true], joinType=[inner])
>     LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>     LogicalAggregate(group=[{}], m=[MIN($0)], c=[COUNT()], d=[COUNT($0)])
>       LogicalProject(DEPTNO=[$0])
>         LogicalFilter(condition=[=($cor0.JOB, $1)])
>           LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
> {code}
> It should be a Correlate, instead of a Join.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to