You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jc...@apache.org on 2017/06/20 10:12:51 UTC
calcite git commit: [CALCITE-1852] Fix for UnionMergeRule to deal
correctly with EXCEPT [Forced Update!]
Repository: calcite
Updated Branches:
refs/heads/master 7cdf4d04b -> f63a65a8c (forced update)
[CALCITE-1852] Fix for UnionMergeRule to deal correctly with EXCEPT
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/f63a65a8
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/f63a65a8
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/f63a65a8
Branch: refs/heads/master
Commit: f63a65a8c6ffd9a771e27ef0446496c6b67baeea
Parents: db95f5b
Author: Jesus Camacho Rodriguez <jc...@apache.org>
Authored: Tue Jun 20 10:22:24 2017 +0100
Committer: Jesus Camacho Rodriguez <jc...@apache.org>
Committed: Tue Jun 20 11:12:37 2017 +0100
----------------------------------------------------------------------
.../calcite/rel/rules/UnionMergeRule.java | 3 +-
.../apache/calcite/test/RelOptRulesTest.java | 30 +++++++++
.../org/apache/calcite/test/RelOptRulesTest.xml | 70 ++++++++++++++++++++
3 files changed, 102 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/f63a65a8/core/src/main/java/org/apache/calcite/rel/rules/UnionMergeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/UnionMergeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/UnionMergeRule.java
index 39bb474..20fbcd9 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/UnionMergeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/UnionMergeRule.java
@@ -115,7 +115,8 @@ public class UnionMergeRule extends RelOptRule {
// Combine the inputs from the bottom set-op with the other inputs from
// the top set-op.
final RelBuilder relBuilder = call.builder();
- if (setOpClass.isInstance(call.rel(2))) {
+ if (setOpClass.isInstance(call.rel(2))
+ && !Minus.class.isAssignableFrom(setOpClass)) {
relBuilder.push(topOp.getInput(0));
relBuilder.pushAll(bottomOp.getInputs());
// topOp.getInputs().size() may be more than 2
http://git-wip-us.apache.org/repos/asf/calcite/blob/f63a65a8/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 891ea10..db29c0f 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -1100,6 +1100,36 @@ public class RelOptRulesTest extends RelOptTestBase {
+ ") aa\n");
}
+ @Test
+ public void testMinusMergeRule() throws Exception {
+ HepProgram program = new HepProgramBuilder()
+ .addRuleInstance(ProjectSetOpTransposeRule.INSTANCE)
+ .addRuleInstance(ProjectRemoveRule.INSTANCE)
+ .addRuleInstance(UnionMergeRule.MINUS_INSTANCE)
+ .build();
+
+ checkPlanning(program,
+ "select * from (\n"
+ + "select * from (\n"
+ + " select name, deptno from\n"
+ + " (\n"
+ + " select name, deptno, count(1) from dept group by name, deptno\n"
+ + " except all\n"
+ + " select name, deptno, 1 from dept\n"
+ + " ) subq\n"
+ + " except all\n"
+ + " select name, deptno from\n"
+ + " (\n"
+ + " select name, deptno, 1 from dept\n"
+ + " except all\n"
+ + " select name, deptno, count(1) from dept group by name, deptno\n"
+ + " ) subq2\n"
+ + ") a\n"
+ + "except all\n"
+ + "select name, deptno from dept\n"
+ + ") aa\n");
+ }
+
/** Tests that a filters is combined are combined if they are identical,
* even if one of them originates in an ON clause of a JOIN. */
@Test public void testMergeJoinFilter() throws Exception {
http://git-wip-us.apache.org/repos/asf/calcite/blob/f63a65a8/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 90f43f2..ac2b30f 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -206,6 +206,76 @@ LogicalProject(NAME=[$0], DEPTNO=[$1])
]]>
</Resource>
</TestCase>
+ <TestCase name="testMinusMergeRule">
+ <Resource name="sql">
+ <![CDATA[select * from (
+select * from (
+ select name, deptno from
+ (
+ select name, deptno, count(1) from dept group by name, deptno
+ except all
+ select name, deptno, 1 from dept
+ ) subq
+ except all
+ select name, deptno from
+ (
+ select name, deptno, 1 from dept
+ except all
+ select name, deptno, count(1) from dept group by name, deptno
+ ) subq2
+) a
+except all
+select name, deptno from dept
+) aa
+]]>
+ </Resource>
+ <Resource name="planAfter">
+ <![CDATA[
+LogicalMinus(all=[true])
+ LogicalProject(NAME=[$0], DEPTNO=[$1])
+ LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
+ LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalProject(NAME=[$0], DEPTNO=[$1])
+ LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[1])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalMinus(all=[true])
+ LogicalProject(NAME=[$0], DEPTNO=[$1])
+ LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[1])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalProject(NAME=[$0], DEPTNO=[$1])
+ LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
+ LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalProject(NAME=[$1], DEPTNO=[$0])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+]]>
+ </Resource>
+ <Resource name="planBefore">
+ <![CDATA[
+LogicalProject(NAME=[$0], DEPTNO=[$1])
+ LogicalMinus(all=[true])
+ LogicalProject(NAME=[$0], DEPTNO=[$1])
+ LogicalMinus(all=[true])
+ LogicalProject(NAME=[$0], DEPTNO=[$1])
+ LogicalMinus(all=[true])
+ LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
+ LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[1])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalProject(NAME=[$0], DEPTNO=[$1])
+ LogicalMinus(all=[true])
+ LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[1])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
+ LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalProject(NAME=[$1], DEPTNO=[$0])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+]]>
+ </Resource>
+ </TestCase>
<TestCase name="testExtractJoinFilterRule">
<Resource name="sql">
<![CDATA[select 1 from emp inner join dept on emp.deptno=dept.deptno]]>