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

Materialized view rewriting algorithm throws IndexOutOfBoundsException

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

      Description

      Repro

      +    sql("select \"deptno\", \"empid\", \"salary\", sum(1) "
      +            + "from \"emps\"\n"
      +            + "group by \"deptno\", \"empid\", \"salary\"",
      +        "select sum(1) "
      +            + "from \"emps\"\n"
      +            + "join \"depts\" on \"depts\".\"deptno\" = \"empid\" group by \"empid\", \"depts\".\"deptno\"")
      +        .withResultContains(
      +            "EnumerableCalc(expr#0..1=[{inputs}], EXPR$0=[$t1])\n"
      +                + "  EnumerableAggregate(group=[{1}], EXPR$0=[$SUM0($3)])\n"
      +                + "    EnumerableHashJoin(condition=[=($1, $4)], joinType=[inner])\n"
      +                + "      EnumerableTableScan(table=[[hr, m0]])")
      +        .ok();
      

      Error

      Next exception 1: [CIRCULAR REFERENCE SQLException]
                  Next exception 2: [CIRCULAR REFERENCE RuntimeException]
                  Next exception 3: java.lang.IndexOutOfBoundsException: index (2) must be less than size (2)
                      at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
                      at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
                      at com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:67)
                      at org.apache.calcite.rex.RexBuilder.makeInputRef(RexBuilder.java:853)
                      at org.apache.calcite.rel.rules.materialize.MaterializedViewRule$3.visitInputRef(MaterializedViewRule.java:1217)
                      at org.apache.calcite.rel.rules.materialize.MaterializedViewRule$3.visitInputRef(MaterializedViewRule.java:1181)
                      at org.apache.calcite.rex.RexInputRef.accept(RexInputRef.java:112)
                      at org.apache.calcite.rex.RexShuttle.apply(RexShuttle.java:277)
                      at org.apache.calcite.rel.rules.materialize.MaterializedViewRule.shuttleReferences(MaterializedViewRule.java:1242)
                      at org.apache.calcite.rel.rules.materialize.MaterializedViewAggregateRule.rewriteView(MaterializedViewAggregateRule.java:728)
                      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:238)
                      at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:540)
                      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)
      

       

        Attachments

        Issue Links

          Activity

            People

            • Assignee:
              vgarg Vineet Garg
              Reporter:
              vgarg Vineet Garg

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

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

                  Issue deployment