[ 
https://issues.apache.org/jira/browse/CALCITE-2801?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Haisheng Yuan resolved CALCITE-2801.
------------------------------------
       Resolution: Fixed
    Fix Version/s: 1.21.0

Fixed in 
https://github.com/apache/calcite/commit/78251a196543a51b67f43b21f484ffcc8a8aa3f9,
 thanks for the PR, [~hequn8128]!

> 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
>             Fix For: 1.21.0
>
>          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)

Reply via email to