Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-1513

Correlated NOT IN query throws AssertionError

    XMLWordPrintableJSON

    Details

      Description

      A correlated NOT IN query throws AssertionError during decorrelation. Here is a patch that reproduces the case:

      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 *
      

      And here is the stack:

      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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vgarg Vineet Garg
                Reporter:
                julianhyde Julian Hyde
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m