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

AggregateOnProjectToAggregateUnifyRule ignores Project incorrectly when its Mapping breaks ordering

    XMLWordPrintableJSON

Details

    Description

      Add the following test to MaterializationTest:

      @Test public void testAggregateGroupSetsRollUp0() {
          checkMaterialize(
              "select \"empid\", \"deptno\", count(*) as c, sum(\"salary\") as s from \"emps\" "
                  + "group by \"empid\", \"deptno\"",
              "select count(*) + 1 as c,  \"deptno\" from \"emps\" group by cube(\"deptno\", \"empid\")",
              HR_FKUK_MODEL,
              CalciteAssert.checkResultContains(
                  "EnumerableCalc(expr#0..2=[{inputs}], expr#3=[1], "
                      + "expr#4=[+($t2, $t3)], C=[$t4], deptno=[$t1])\n"
                      + "  EnumerableAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {1}, {}]], agg#0=[$SUM0($2)])\n"
                      + "    EnumerableTableScan(table=[[hr, m0]])"));
        }
      

      We got error:

      Caused by: java.lang.IllegalArgumentException: must be sorted: [{0, 1}, {1}, {0}, {}]
      	at org.apache.calcite.rel.core.Aggregate$Group.induce(Aggregate.java:472)
      	at org.apache.calcite.rel.mutable.MutableAggregate.getGroupType(MutableAggregate.java:83)
      	at org.apache.calcite.plan.SubstitutionVisitor.unifyAggregates(SubstitutionVisitor.java:1281)
      	at org.apache.calcite.plan.SubstitutionVisitor$AggregateOnProjectToAggregateUnifyRule.apply(SubstitutionVisitor.java:1345)
      	at org.apache.calcite.plan.SubstitutionVisitor.go(SubstitutionVisitor.java:531)
      	at org.apache.calcite.plan.SubstitutionVisitor.go(SubstitutionVisitor.java:466)
      	at org.apache.calcite.plan.MaterializedViewSubstitutionVisitor.go(MaterializedViewSubstitutionVisitor.java:56)
      	at org.apache.calcite.plan.RelOptMaterializations.substitute(RelOptMaterializations.java:200)
      	at org.apache.calcite.plan.RelOptMaterializations.useMaterializedViews(RelOptMaterializations.java:72)
      	at org.apache.calcite.plan.volcano.VolcanoPlanner.registerMaterializations(VolcanoPlanner.java:348)
      	at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:584)
      

      The reason is that Mappings.apply2 doesn't sort.

      Attachments

        Issue Links

          Activity

            People

              donnyzone Feng Zhu
              hyuan Haisheng Yuan
              Votes:
              0 Vote for this issue
              Watchers:
              4 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 - 1.5h
                  1.5h