This is an automated email from the ASF dual-hosted git repository.
hyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new a136dc4 [CALCITE-3939] Change UnionEliminatorRule and
ProjectRemoveRule to auto pruning SubstitutionRule (Botong Huang)
a136dc4 is described below
commit a136dc4884677bca7496a783c854220834440058
Author: botong.huang <[email protected]>
AuthorDate: Sun Apr 19 11:22:43 2020 -0700
[CALCITE-3939] Change UnionEliminatorRule and ProjectRemoveRule to auto
pruning SubstitutionRule (Botong Huang)
UnionEliminatorRule and ProjectRemoveRule are both pruning rules for a
RelNode.
They can also become SubstitutionRule with autoprune enabled.
Close #1927
---
.../calcite/rel/rules/ProjectRemoveRule.java | 13 +++---------
.../calcite/rel/rules/UnionEliminatorRule.java | 23 +++++++++++-----------
2 files changed, 15 insertions(+), 21 deletions(-)
diff --git
a/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java
b/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java
index e957dbe..a1435fd 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java
@@ -22,13 +22,9 @@ import org.apache.calcite.plan.SubstitutionRule;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.core.RelFactories;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.tools.RelBuilderFactory;
-import java.util.List;
-
/**
* Planner rule that,
* given a {@link org.apache.calcite.rel.core.Project} node that
@@ -71,8 +67,7 @@ public class ProjectRemoveRule extends RelOptRule implements
SubstitutionRule {
childProject.getInput(), childProject.getProjects(),
project.getRowType());
}
- RelNode child = call.getPlanner().register(stripped, project);
- call.transformTo(child);
+ call.transformTo(stripped);
}
/**
@@ -88,9 +83,7 @@ public class ProjectRemoveRule extends RelOptRule implements
SubstitutionRule {
project.getInput().getRowType());
}
- @Deprecated // to be removed before 1.5
- public static boolean isIdentity(List<? extends RexNode> exps,
- RelDataType childRowType) {
- return RexUtil.isIdentity(exps, childRowType);
+ @Override public boolean autoPruneOld() {
+ return true;
}
}
diff --git
a/core/src/main/java/org/apache/calcite/rel/rules/UnionEliminatorRule.java
b/core/src/main/java/org/apache/calcite/rel/rules/UnionEliminatorRule.java
index 01d891d..006d6fc 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/UnionEliminatorRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/UnionEliminatorRule.java
@@ -18,6 +18,7 @@ package org.apache.calcite.rel.rules;
import org.apache.calcite.plan.RelOptRule;
import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.SubstitutionRule;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.rel.core.Union;
import org.apache.calcite.rel.logical.LogicalUnion;
@@ -28,7 +29,8 @@ import org.apache.calcite.tools.RelBuilderFactory;
* Union call by eliminating the Union operator altogether in the case the call
* consists of only one input.
*/
-public class UnionEliminatorRule extends RelOptRule {
+public class UnionEliminatorRule extends RelOptRule
+ implements SubstitutionRule {
public static final UnionEliminatorRule INSTANCE =
new UnionEliminatorRule(LogicalUnion.class,
RelFactories.LOGICAL_BUILDER);
@@ -44,18 +46,17 @@ public class UnionEliminatorRule extends RelOptRule {
//~ Methods ----------------------------------------------------------------
- public void onMatch(RelOptRuleCall call) {
+ @Override public boolean matches(RelOptRuleCall call) {
Union union = call.rel(0);
- if (union.getInputs().size() != 1) {
- return;
- }
- if (!union.all) {
- return;
- }
-
- // REVIEW jvs 14-Mar-2006: why don't we need to register
- // the equivalence here like we do in AggregateRemoveRule?
+ return union.all && union.getInputs().size() == 1;
+ }
+ public void onMatch(RelOptRuleCall call) {
+ Union union = call.rel(0);
call.transformTo(union.getInputs().get(0));
}
+
+ @Override public boolean autoPruneOld() {
+ return true;
+ }
}