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

Correlated scalar sub-query with multiple aggregates gives AssertionError

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.12.0
    • Component/s: None
    • Labels:
      None

      Description

      Caused by: java.lang.AssertionError at org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(RelDecorrelator.java:456)

      The code is:

          final Frame frame = getInvoke(oldInput, rel);
          if (frame == null) {
            // If input has not been rewritten, do not rewrite this rel.
            return null;
          }
          assert !frame.corVarOutputPos.isEmpty();
      

      Seems like it's no need to assert the corVarOutputPos because in some cases, the correlate has been fully rewritten.

        Issue Links

          Activity

          Hide
          julianhyde Julian Hyde added a comment -

          Can you provide a test case for this?

          Show
          julianhyde Julian Hyde added a comment - Can you provide a test case for this?
          Hide
          ykt836 Kurt Young added a comment -

          Julian Hyde I used this query to reproduce:

          select sum(l_extendedprice)
          from lineitem, part
          where
               p_partkey = l_partkey
               and l_quantity > (
                 select avg(l_quantity)
                 from lineitem
                 where l_partkey = p_partkey
              )
          

          There are two Aggregates in the operator tree, one with avg(l_quantity) will be affected by the correlation, but the outer aggregation sum(l_extendedprice) is not.

          Show
          ykt836 Kurt Young added a comment - Julian Hyde I used this query to reproduce: select sum(l_extendedprice) from lineitem, part where p_partkey = l_partkey and l_quantity > ( select avg(l_quantity) from lineitem where l_partkey = p_partkey ) There are two Aggregates in the operator tree, one with avg(l_quantity) will be affected by the correlation, but the outer aggregation sum(l_extendedprice) is not.
          Hide
          julianhyde Julian Hyde added a comment -
          Show
          julianhyde Julian Hyde added a comment - I have a code test case: see https://github.com/julianhyde/calcite/tree/1543-decorrelate-aggregate-scalar .
          Hide
          ykt836 Kurt Young added a comment -

          Hi Julian Hyde, i checked your test case, and you missed one thing:
          "you need to call with(true) to enable the assertion", i also left comments in your commit.
          Thanks for reproducing this.

          Show
          ykt836 Kurt Young added a comment - Hi Julian Hyde , i checked your test case, and you missed one thing: "you need to call with(true) to enable the assertion", i also left comments in your commit. Thanks for reproducing this.
          Hide
          julianhyde Julian Hyde added a comment -

          Looks good; I have merged to my master branch and will push to Apache master after 1.11 is released.

          Show
          julianhyde Julian Hyde added a comment - Looks good; I have merged to my master branch and will push to Apache master after 1.11 is released.
          Hide
          julianhyde Julian Hyde added a comment -
          Show
          julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/408285f0 . Thanks for the PR, Kurt Young !
          Hide
          julianhyde Julian Hyde added a comment -

          Resolved in release 1.12.0 (2017-03-24).

          Show
          julianhyde Julian Hyde added a comment - Resolved in release 1.12.0 (2017-03-24).

            People

            • Assignee:
              julianhyde Julian Hyde
              Reporter:
              ykt836 Kurt Young
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development