amaliujia commented on a change in pull request #2437:
URL: https://github.com/apache/calcite/pull/2437#discussion_r652154431
##########
File path: core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
##########
@@ -1028,6 +1028,39 @@ LogicalProject(MGR=[$0], SUM_SAL=[$2])
LogicalAggregate(group=[{0, 1}], SUM_SAL=[SUM($2)])
LogicalProject(MGR=[$3], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testAggregateUnionTransposeWithOneUniqueInput">
+ <Resource name="sql">
+ <![CDATA[select deptno, SUM(t) from (
+select deptno, 1 as t from sales.emp e1
+union all
+select distinct deptno, 2 as t from sales.emp e2)
+group by deptno]]>
+ </Resource>
+ <Resource name="planBefore">
+ <![CDATA[
+LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
+ LogicalUnion(all=[true])
+ LogicalProject(DEPTNO=[$7], T=[1])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalAggregate(group=[{0, 1}])
+ LogicalProject(DEPTNO=[$7], T=[2])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ <Resource name="planAfter">
+ <![CDATA[
+LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
Review comment:
Ok, then the pushdown make senses since it does a pre-agg before UNION
and then post-agg after UNION, that gives correct result.
And if all inputs are already unique, then there is no need to push down
agg. In this case, are you aware if there is a test existing to verify the
return case? (I tried to search testAggregateUnionTransposeWithAllUniqueInputs
or just testAggregateUnionTranspose but only found your new test case).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]