You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Haisheng Yuan (JIRA)" <ji...@apache.org> on 2019/06/30 20:05:00 UTC

[jira] [Commented] (CALCITE-2801) Check input type in AggregateUnionAggregateRule when remove the bottom Aggregate

    [ https://issues.apache.org/jira/browse/CALCITE-2801?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16875854#comment-16875854 ] 

Haisheng Yuan commented on CALCITE-2801:
----------------------------------------

I have updated the patch by preserving the union aliases, and add 1 more test case for the coverage.

> Check input type in AggregateUnionAggregateRule when remove the bottom Aggregate
> --------------------------------------------------------------------------------
>
>                 Key: CALCITE-2801
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2801
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Hequn Cheng
>            Assignee: Hequn Cheng
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> In {{AggregateUnionAggregateRule}}, we may remove the bottom Aggregate and use it's input as the new input of Union directly. However, the bottom Aggregate and it's input may not share the same row type. As Union requires all inputs with a same row type, once we remove the bottom Aggregate, an exception will be thrown.
> The exception can be reproduced by the following test:
> {code:java}
>   @Test public void testPullAggregateThroughUnion() {
>     HepProgram program = new HepProgramBuilder()
>         .addRuleInstance(AggregateProjectMergeRule.INSTANCE)
>         .addRuleInstance(AggregateUnionAggregateRule.INSTANCE)
>         .build();
>     final String sql = "select job, deptno from"
>             + " (select job, deptno from emp as e1"
>             + " group by job, deptno"
>             + "  union all"
>             + " select job, deptno from emp as e2"
>             + " group by job, deptno)"
>             + " group by job, deptno";
>     sql(sql).with(program).check();
>   }
> {code}
> {code:java}
> java.lang.IllegalArgumentException: Cannot compute compatible row type for arguments to set op: RecordType(VARCHAR(10) JOB, INTEGER DEPTNO), RecordType(INTEGER EMPNO, VARCHAR(20) ENAME, VARCHAR(10) JOB, INTEGER MGR, TIMESTAMP(0) HIREDATE, INTEGER SAL, INTEGER COMM, INTEGER DEPTNO, BOOLEAN SLACKER)
> 	at org.apache.calcite.rel.core.SetOp.deriveRowType(SetOp.java:111)
> 	at org.apache.calcite.rel.AbstractRelNode.getRowType(AbstractRelNode.java:222)
> 	at org.apache.calcite.tools.RelBuilder$Frame.<init>(RelBuilder.java:2378)
> 	at org.apache.calcite.tools.RelBuilder$Frame.<init>(RelBuilder.java:2363)
> 	at org.apache.calcite.tools.RelBuilder.push(RelBuilder.java:260)
> 	at org.apache.calcite.tools.RelBuilder.setOp(RelBuilder.java:1559)
> 	at org.apache.calcite.tools.RelBuilder.union(RelBuilder.java:1579)
> 	at org.apache.calcite.tools.RelBuilder.union(RelBuilder.java:1569)
> 	at org.apache.calcite.rel.rules.AggregateUnionAggregateRule.onMatch(AggregateUnionAggregateRule.java:130)
> 	at org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:319)
> 	at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:559)
> 	at org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:418)
> 	at org.apache.calcite.plan.hep.HepPlanner.executeInstruction(HepPlanner.java:255)
> 	at org.apache.calcite.plan.hep.HepInstruction$RuleInstance.execute(HepInstruction.java:127)
> 	at org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:214)
> 	at org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:201)
> 	at org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:206)
> 	at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:334)
> 	at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:317)
> 	at org.apache.calcite.test.RelOptRulesTest.testPullAggregateThroughUnion
> {code}
> I see two option to solve the problem:
> - Check the input type in {{AggregateUnionAggregateRule}} and exit the rule directly.
> - Add a Project with a same row type to the bottom Aggregate. 
> What do you guys think? Thanks a lot.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)