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

Rewriting for materialized view consisting of group by on join keys fails with Mappings$NoElementException

    XMLWordPrintableJSON

Details

    Description

      Test case

      +  @Test public void testAggregateOnJoinKeys() {
      +    checkMaterialize(
      +        "select \"deptno\", \"empid\", \"salary\"\n"
      +            + "from \"emps\"\n"
      +            + "group by \"deptno\", \"empid\", \"salary\"",
      +     "select \"empid\", \"depts\".\"deptno\" \n"
      +        + "from \"emps\"\n"
      +        + "join \"depts\" on \"depts\".\"deptno\" = \"empid\" group by \"empid\", \"depts\".\"deptno\"",
      +        HR_FKUK_MODEL,
      +        CalciteAssert.checkResultContains(
      +            "EnumerableCalc(expr#0=[{inputs}], empid=[$t0], empid0=[$t0])\n"
      +              + "  EnumerableAggregate(group=[{1}])\n"
      +                + "    EnumerableHashJoin(condition=[=($1, $3)], joinType=[inner])\n"
      +                + "      EnumerableTableScan(table=[[hr, m0]])"));
      +  }
      +
      

      Error:

      Caused by: java.lang.RuntimeException: Error while applying rule MaterializedViewAggregateRule(Aggregate), args [rel#64476:EnumerableAggregate.ENUMERABLE.[](input=RelSubset#64475,group={0, 1})]
                      at org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:260)
                      at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:634)
                      at org.apache.calcite.tools.Programs.lambda$standard$3(Programs.java:286)
                      at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:346)
                      at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:165)
                      at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:290)
                      at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:207)
                      at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:634)
                      at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:498)
                      at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:468)
                      at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:231)
                      at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
                      at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
                      at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
                      ... 16 more
                  Next exception 1: [CIRCULAR REFERENCE SQLException]
                  Next exception 2: [CIRCULAR REFERENCE RuntimeException]
                  Next exception 3: org.apache.calcite.util.mapping.Mappings$NoElementException: source #0 has no target in mapping [size=1, sourceCount=2, targetCount=7, elements=[1:1]]
                      at org.apache.calcite.util.mapping.Mappings$AbstractMapping.getTarget(Mappings.java:881)
                      at org.apache.calcite.rel.rules.materialize.MaterializedViewAggregateRule.rewriteView(MaterializedViewAggregateRule.java:677)
                      at org.apache.calcite.rel.rules.materialize.MaterializedViewRule.perform(MaterializedViewRule.java:485)
                      at org.apache.calcite.rel.rules.materialize.MaterializedViewOnlyAggregateRule.onMatch(MaterializedViewOnlyAggregateRule.java:63)
                      at org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:233)
                      at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:634)
                      at org.apache.calcite.tools.Programs.lambda$standard$3(Programs.java:286)
                      at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:346)
                      at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:165)
                      at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:290)
                      at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:207)
                      at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:634)
                      at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:498)
                      at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:468)
                      at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:231)
                      at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
                      at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
                      at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
                      ... 16 more
                      Caused by: [CIRCULAR REFERENCE PlaceholderException]
      

      Attachments

        Issue Links

          Activity

            People

              vgarg Vineet Garg
              vgarg Vineet Garg
              Votes:
              0 Vote for this issue
              Watchers:
              2 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