[ 
https://issues.apache.org/jira/browse/CALCITE-1513?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Julian Hyde updated CALCITE-1513:
---------------------------------
    Labels: sub-query  (was: )

> Correlated NOT IN query throws AssertionError
> ---------------------------------------------
>
>                 Key: CALCITE-1513
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1513
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Julian Hyde
>            Assignee: Julian Hyde
>              Labels: sub-query
>
> A correlated NOT IN query throws AssertionError during decorrelation. Here is 
> a patch that reproduces the case:
> {noformat}
> diff --git a/core/src/test/resources/sql/subquery.iq 
> b/core/src/test/resources/sql/subquery.iq
> index ad71655..975aae1 100644
> --- a/core/src/test/resources/sql/subquery.iq
> +++ b/core/src/test/resources/sql/subquery.iq
> @@ -370,6 +370,22 @@ where e.job not in (
>  !plan
>  !}
>  
> +# Correlated condition in NOT IN.
> +# Tested on Oracle.
> +select count(*) as c
> +from "scott".emp as e
> +where sal + 100 not in (
> +  select comm
> +  from "scott".emp
> +  where job = e.job);
> +     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM   
>   DEPTNO
> +---------- ---------- --------- ---------- --------- ---------- ---------- 
> ----------
> +      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300   
>       30
> +      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500   
>       30
> +      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400   
>       30
> +      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0   
>       30
> +!ok
> +
>  # [CALCITE-864] Correlation variable has incorrect row type if it is 
> populated
>  # by right side of a Join
>  select *
> {noformat}
> And here is the stack:
> {noformat}
> java.lang.AssertionError: Internal error: While invoking method 'public 
> org.apache.calcite.sql2rel.RelDecorrelator$Frame 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(org.apache.calcite.rel.logical.LogicalAggregate)'
>       at org.apache.calcite.util.Util.newInternal(Util.java:792)
>       at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:534)
>       at 
> org.apache.calcite.sql2rel.RelDecorrelator.getInvoke(RelDecorrelator.java:601)
>       at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:242)
>       at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:211)
>       at 
> org.apache.calcite.tools.Programs$DecorrelateProgram.run(Programs.java:370)
>       at 
> org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:351)
>       at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:155)
>       at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:286)
>       at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:195)
>       at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:748)
>       at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:610)
>       at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:580)
> Caused by: java.lang.reflect.InvocationTargetException
>       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.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:531)
>       ... 29 more
> Caused by: java.lang.AssertionError
>       at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(RelDecorrelator.java:454)
>       ... 34 more{noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to