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

AggregateJoinTransposeRule fails to preserve row type

    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

      Here is the sql to reproduce the failure:

      select e.deptno
      from sales.emp as e join sales.dept as d on e.deptno = d.deptno
      group by e.deptno
      

      After push the aggregator past join, the RowType seems been changed, and gives the following error:

      java.lang.AssertionError: Internal error: Cannot add expression of different type to set:
      set type is RecordType(INTEGER NOT NULL DEPTNO, INTEGER NOT NULL DEPTNO0) NOT NULL
      expression type is RecordType(INTEGER NOT NULL DEPTNO, INTEGER NOT NULL DEPTNO0, VARCHAR(10) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL NAME) NOT NULL
      set is rel#20:LogicalAggregate(input=HepRelVertex#19,group={7, 9})
      expression is LogicalJoin#23
      
      	at org.apache.calcite.util.Util.newInternal(Util.java:780)
      	at org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:384)
      	at org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:57)
      	at org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:225)
      	at org.apache.calcite.rel.rules.AggregateJoinTransposeRule.onMatch(AggregateJoinTransposeRule.java:342)
      

        Issue Links

          Activity

          Hide
          julianhyde Julian Hyde added a comment -

          Cannot reproduce. I tried

            @Test public void testAggJoin() {
              final String sql = "select e.deptno\n"
                  + "from emp as e join dept as d on e.deptno = d.deptno\n"
                  + "group by e.deptno\n";
              withEmpDept(sql).runs();
            }
          
          Show
          julianhyde Julian Hyde added a comment - Cannot reproduce. I tried @Test public void testAggJoin() { final String sql = "select e.deptno\n" + "from emp as e join dept as d on e.deptno = d.deptno\n" + "group by e.deptno\n" ; withEmpDept(sql).runs(); }
          Hide
          ykt836 Kurt Young added a comment -

          Hi Julian Hyde, i can reproduce by adding a test case to RelOptRulesTest

            @Test public void testPushAggregateThroughJoin() throws Exception {
              final HepProgram preProgram = new HepProgramBuilder()
                      .addRuleInstance(AggregateProjectMergeRule.INSTANCE)
                      .build();
              final HepProgram program = new HepProgramBuilder()
                      .addRuleInstance(AggregateJoinTransposeRule.EXTENDED)
                      .build();
              final String sql = "select e.deptno\n"
                      + "from sales.emp as e join sales.dept as d on e.deptno = d.deptno\n"
                      + "group by e.deptno";
              checkPlanning(tester, preProgram, new HepPlanner(program), sql);
            }
          

          Can you try this again?

          Show
          ykt836 Kurt Young added a comment - Hi Julian Hyde , i can reproduce by adding a test case to RelOptRulesTest @Test public void testPushAggregateThroughJoin() throws Exception { final HepProgram preProgram = new HepProgramBuilder() .addRuleInstance(AggregateProjectMergeRule.INSTANCE) .build(); final HepProgram program = new HepProgramBuilder() .addRuleInstance(AggregateJoinTransposeRule.EXTENDED) .build(); final String sql = "select e.deptno\n" + "from sales.emp as e join sales.dept as d on e.deptno = d.deptno\n" + "group by e.deptno" ; checkPlanning(tester, preProgram, new HepPlanner(program), sql); } Can you try this again?
          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/91102baf . 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:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development