You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2015/04/16 18:16:43 UTC
[3/5] incubator-calcite git commit: [CALCITE-674] Add a SWAP_OUTER
static instance to JoinCommuteRule (Maryann Xue)
[CALCITE-674] Add a SWAP_OUTER static instance to JoinCommuteRule (Maryann Xue)
Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/ec925e2d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/ec925e2d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/ec925e2d
Branch: refs/heads/master
Commit: ec925e2d337d61a0bb4cb7662c580c47e148adad
Parents: 2fdcc5f
Author: Julian Hyde <jh...@apache.org>
Authored: Thu Apr 9 14:55:58 2015 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Apr 13 14:55:10 2015 -0700
----------------------------------------------------------------------
.../calcite/rel/rules/JoinCommuteRule.java | 24 +++++++++++++++-----
.../apache/calcite/test/RelOptRulesTest.java | 10 ++++++++
.../org/apache/calcite/test/RelOptRulesTest.xml | 22 ++++++++++++++++++
3 files changed, 50 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/ec925e2d/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
index b90ea97..36673f1 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
@@ -41,7 +41,8 @@ import java.util.List;
* Planner rule that permutes the inputs to a
* {@link org.apache.calcite.rel.core.Join}.
*
- * <p>Outer joins cannot be permuted.
+ * <p>Permutation of outer joins can be turned on/off by specifying the
+ * swapOuter flag in the constructor.
*
* <p>To preserve the order of columns in the output row, the rule adds a
* {@link org.apache.calcite.rel.core.Project}.
@@ -49,24 +50,35 @@ import java.util.List;
public class JoinCommuteRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
- /** The singleton. */
- public static final JoinCommuteRule INSTANCE = new JoinCommuteRule();
+ /** Instance of the rule that only swaps inner joins. */
+ public static final JoinCommuteRule INSTANCE = new JoinCommuteRule(false);
+
+ /** Instance of the rule that swaps outer joins as well as inner joins. */
+ public static final JoinCommuteRule SWAP_OUTER = new JoinCommuteRule(true);
private final ProjectFactory projectFactory;
+ private final boolean swapOuter;
//~ Constructors -----------------------------------------------------------
/**
* Creates a JoinCommuteRule.
*/
- private JoinCommuteRule() {
- this(LogicalJoin.class, RelFactories.DEFAULT_PROJECT_FACTORY);
+ private JoinCommuteRule(boolean swapOuter) {
+ this(LogicalJoin.class, RelFactories.DEFAULT_PROJECT_FACTORY, swapOuter);
}
+ @Deprecated // to be removed before 2.0
public JoinCommuteRule(Class<? extends Join> clazz,
ProjectFactory projectFactory) {
+ this(clazz, projectFactory, false);
+ }
+
+ public JoinCommuteRule(Class<? extends Join> clazz,
+ ProjectFactory projectFactory, boolean swapOuter) {
super(operand(clazz, any()));
this.projectFactory = projectFactory;
+ this.swapOuter = swapOuter;
}
//~ Methods ----------------------------------------------------------------
@@ -123,7 +135,7 @@ public class JoinCommuteRule extends RelOptRule {
return;
}
- final RelNode swapped = swap(join);
+ final RelNode swapped = swap(join, this.swapOuter);
if (swapped == null) {
return;
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/ec925e2d/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 3663e4f..41017c8 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -49,6 +49,7 @@ import org.apache.calcite.rel.rules.FilterProjectTransposeRule;
import org.apache.calcite.rel.rules.FilterSetOpTransposeRule;
import org.apache.calcite.rel.rules.FilterToCalcRule;
import org.apache.calcite.rel.rules.JoinAddRedundantSemiJoinRule;
+import org.apache.calcite.rel.rules.JoinCommuteRule;
import org.apache.calcite.rel.rules.JoinExtractFilterRule;
import org.apache.calcite.rel.rules.JoinPushTransitivePredicatesRule;
import org.apache.calcite.rel.rules.JoinToMultiJoinRule;
@@ -1500,6 +1501,15 @@ public class RelOptRulesTest extends RelOptTestBase {
+ "group by e.empno,d.deptno");
}
+ @Test public void testSwapOuterJoin() throws Exception {
+ final HepProgram program = new HepProgramBuilder()
+ .addMatchLimit(1)
+ .addRuleInstance(JoinCommuteRule.SWAP_OUTER)
+ .build();
+ checkPlanning(program,
+ "select 1 from sales.dept d left outer join sales.emp e"
+ + " on d.deptno = e.deptno");
+ }
}
// End RelOptRulesTest.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/ec925e2d/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 83154af..dea51a9 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -3479,4 +3479,26 @@ LogicalProject(EMPNO=[$0], EXPR$1=[$2])
]]>
</Resource>
</TestCase>
+ <TestCase name="testSwapOuterJoin">
+ <Resource name="sql">
+ <![CDATA[select 1 from sales.dept d left outer join sales.emp e on d.deptno = e.deptno]]>
+ </Resource>
+ <Resource name="planBefore">
+ <![CDATA[
+LogicalProject(EXPR$0=[1])
+ LogicalJoin(condition=[=($0, $9)], joinType=[left])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ <Resource name="planAfter">
+ <![CDATA[
+LogicalProject(EXPR$0=[1])
+ LogicalProject(DEPTNO=[$9], NAME=[$10], EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO0=[$7], SLACKER=[$8])
+ LogicalJoin(condition=[=($9, $7)], joinType=[right])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+]]>
+ </Resource>
+ </TestCase>
</Root>