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 2014/11/14 22:32:41 UTC
[33/58] [abbrv] [partial] incubator-calcite git commit: [CALCITE-306]
Standardize code style for "import package.*; "
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/FilterProjectTransposeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/FilterProjectTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/FilterProjectTransposeRule.java
index 2e07d23..2f5b720 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/FilterProjectTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/FilterProjectTransposeRule.java
@@ -14,27 +14,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.rex.*;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexOver;
/**
- * PushFilterPastProjectRule implements the rule for pushing a {@link FilterRel}
- * past a {@link ProjectRel}.
+ * Planner rule that pushes
+ * a {@link org.apache.calcite.rel.logical.LogicalFilter}
+ * past a {@link org.apache.calcite.rel.logical.LogicalProject}.
*/
-public class PushFilterPastProjectRule extends RelOptRule {
+public class FilterProjectTransposeRule extends RelOptRule {
/** The default instance of
- * {@link org.eigenbase.rel.rules.PushFilterPastJoinRule}.
+ * {@link org.apache.calcite.rel.rules.FilterProjectTransposeRule}.
*
* <p>It matches any kind of join or filter, and generates the same kind of
* join and filter. It uses null values for {@code filterFactory} and
* {@code projectFactory} to achieve this. */
- public static final PushFilterPastProjectRule INSTANCE =
- new PushFilterPastProjectRule(
- FilterRelBase.class, null,
- ProjectRelBase.class, null);
+ public static final FilterProjectTransposeRule INSTANCE =
+ new FilterProjectTransposeRule(
+ Filter.class, null,
+ Project.class, null);
private final RelFactories.FilterFactory filterFactory;
private final RelFactories.ProjectFactory projectFactory;
@@ -42,15 +49,15 @@ public class PushFilterPastProjectRule extends RelOptRule {
//~ Constructors -----------------------------------------------------------
/**
- * Creates a PushFilterPastProjectRule.
+ * Creates a FilterProjectTransposeRule.
*
* <p>If {@code filterFactory} is null, creates the same kind of filter as
* matched in the rule. Similarly {@code projectFactory}.</p>
*/
- public PushFilterPastProjectRule(
- Class<? extends FilterRelBase> filterClass,
+ public FilterProjectTransposeRule(
+ Class<? extends Filter> filterClass,
RelFactories.FilterFactory filterFactory,
- Class<? extends ProjectRelBase> projectClass,
+ Class<? extends Project> projectClass,
RelFactories.ProjectFactory projectFactory) {
super(
operand(filterClass,
@@ -63,8 +70,8 @@ public class PushFilterPastProjectRule extends RelOptRule {
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- final FilterRelBase filterRel = call.rel(0);
- final ProjectRelBase projRel = call.rel(1);
+ final Filter filterRel = call.rel(0);
+ final Project projRel = call.rel(1);
if (RexOver.containsOver(projRel.getProjects(), null)) {
// In general a filter cannot be pushed below a windowing calculation.
@@ -82,9 +89,9 @@ public class PushFilterPastProjectRule extends RelOptRule {
RelNode newFilterRel =
filterFactory == null
- ? filterRel.copy(filterRel.getTraitSet(), projRel.getChild(),
+ ? filterRel.copy(filterRel.getTraitSet(), projRel.getInput(),
newCondition)
- : filterFactory.createFilter(projRel.getChild(), newCondition);
+ : filterFactory.createFilter(projRel.getInput(), newCondition);
RelNode newProjRel =
projectFactory == null
@@ -97,4 +104,4 @@ public class PushFilterPastProjectRule extends RelOptRule {
}
}
-// End PushFilterPastProjectRule.java
+// End FilterProjectTransposeRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/FilterRemoveIsNotDistinctFromRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/FilterRemoveIsNotDistinctFromRule.java b/core/src/main/java/org/apache/calcite/rel/rules/FilterRemoveIsNotDistinctFromRule.java
index d415f2d..85fe7e2 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/FilterRemoveIsNotDistinctFromRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/FilterRemoveIsNotDistinctFromRule.java
@@ -14,35 +14,45 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.sql.fun.*;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
/**
- * Rule to replace isNotDistinctFromOperator with logical equivalent conditions
- * in a {@link FilterRel}.
+ * Planner rule that replaces {@code IS NOT DISTINCT FROM}
+ * in a {@link org.apache.calcite.rel.logical.LogicalFilter}
+ * with logically equivalent operations.
+ *
+ * @see org.apache.calcite.sql.fun.SqlStdOperatorTable#IS_NOT_DISTINCT_FROM
*/
-public final class RemoveIsNotDistinctFromRule extends RelOptRule {
+public final class FilterRemoveIsNotDistinctFromRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
/** The singleton. */
- public static final RemoveIsNotDistinctFromRule INSTANCE =
- new RemoveIsNotDistinctFromRule();
+ public static final FilterRemoveIsNotDistinctFromRule INSTANCE =
+ new FilterRemoveIsNotDistinctFromRule();
//~ Constructors -----------------------------------------------------------
- private RemoveIsNotDistinctFromRule() {
- super(operand(FilterRel.class, any()));
+ private FilterRemoveIsNotDistinctFromRule() {
+ super(operand(LogicalFilter.class, any()));
}
//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
- FilterRel oldFilterRel = call.rel(0);
- RexNode oldFilterCond = oldFilterRel.getCondition();
+ LogicalFilter oldFilter = call.rel(0);
+ RexNode oldFilterCond = oldFilter.getCondition();
if (RexUtil.findOperatorCall(
SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
@@ -57,11 +67,11 @@ public final class RemoveIsNotDistinctFromRule extends RelOptRule {
RemoveIsNotDistinctFromRexShuttle rewriteShuttle =
new RemoveIsNotDistinctFromRexShuttle(
- oldFilterRel.getCluster().getRexBuilder());
+ oldFilter.getCluster().getRexBuilder());
RelNode newFilterRel =
RelOptUtil.createFilter(
- oldFilterRel.getChild(),
+ oldFilter.getInput(),
oldFilterCond.accept(rewriteShuttle));
call.transformTo(newFilterRel);
@@ -99,4 +109,4 @@ public final class RemoveIsNotDistinctFromRule extends RelOptRule {
}
}
-// End RemoveIsNotDistinctFromRule.java
+// End FilterRemoveIsNotDistinctFromRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/FilterSetOpTransposeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/FilterSetOpTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/FilterSetOpTransposeRule.java
index b48fd3f..4e04d0b 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/FilterSetOpTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/FilterSetOpTransposeRule.java
@@ -14,35 +14,41 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rel.core.SetOp;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
import java.util.ArrayList;
import java.util.List;
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
-
/**
- * PushFilterPastSetOpRule implements the rule for pushing a {@link FilterRel}
- * past a {@link SetOpRel}.
+ * Planner rule that pushes a {@link org.apache.calcite.rel.core.Filter}
+ * past a {@link org.apache.calcite.rel.core.SetOp}.
*/
-public class PushFilterPastSetOpRule extends RelOptRule {
- public static final PushFilterPastSetOpRule INSTANCE =
- new PushFilterPastSetOpRule(RelFactories.DEFAULT_FILTER_FACTORY);
+public class FilterSetOpTransposeRule extends RelOptRule {
+ public static final FilterSetOpTransposeRule INSTANCE =
+ new FilterSetOpTransposeRule(RelFactories.DEFAULT_FILTER_FACTORY);
private final RelFactories.FilterFactory filterFactory;
//~ Constructors -----------------------------------------------------------
/**
- * Creates a PushFilterPastSetOpRule.
+ * Creates a FilterSetOpTransposeRule.
*/
- public PushFilterPastSetOpRule(RelFactories.FilterFactory filterFactory) {
+ public FilterSetOpTransposeRule(RelFactories.FilterFactory filterFactory) {
super(
- operand(FilterRelBase.class,
- operand(SetOpRel.class, any())));
+ operand(Filter.class,
+ operand(SetOp.class, any())));
this.filterFactory = filterFactory;
}
@@ -50,8 +56,8 @@ public class PushFilterPastSetOpRule extends RelOptRule {
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- FilterRelBase filterRel = call.rel(0);
- SetOpRel setOpRel = call.rel(1);
+ Filter filterRel = call.rel(0);
+ SetOp setOp = call.rel(1);
RexNode condition = filterRel.getCondition();
@@ -59,10 +65,10 @@ public class PushFilterPastSetOpRule extends RelOptRule {
// condition to reference each setop child
RexBuilder rexBuilder = filterRel.getCluster().getRexBuilder();
List<RelDataTypeField> origFields =
- setOpRel.getRowType().getFieldList();
+ setOp.getRowType().getFieldList();
int[] adjustments = new int[origFields.size()];
List<RelNode> newSetOpInputs = new ArrayList<RelNode>();
- for (RelNode input : setOpRel.getInputs()) {
+ for (RelNode input : setOp.getInputs()) {
RexNode newCondition =
condition.accept(
new RelOptUtil.RexInputConverter(
@@ -74,11 +80,11 @@ public class PushFilterPastSetOpRule extends RelOptRule {
}
// create a new setop whose children are the filters created above
- SetOpRel newSetOpRel =
- setOpRel.copy(setOpRel.getTraitSet(), newSetOpInputs);
+ SetOp newSetOp =
+ setOp.copy(setOp.getTraitSet(), newSetOpInputs);
- call.transformTo(newSetOpRel);
+ call.transformTo(newSetOp);
}
}
-// End PushFilterPastSetOpRule.java
+// End FilterSetOpTransposeRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/FilterTableFunctionTransposeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/FilterTableFunctionTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/FilterTableFunctionTransposeRule.java
index f9f4484..24f6a04 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/FilterTableFunctionTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/FilterTableFunctionTransposeRule.java
@@ -14,45 +14,53 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
-import java.util.*;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalTableFunctionScan;
+import org.apache.calcite.rel.metadata.RelColumnMapping;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
-import org.eigenbase.rel.*;
-import org.eigenbase.rel.metadata.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
/**
- * PushFilterPastTableFunctionRule implements the rule for pushing a
- * {@link FilterRel} past a {@link TableFunctionRel}.
+ * Planner rule that pushes
+ * a {@link org.apache.calcite.rel.logical.LogicalFilter}
+ * past a {@link org.apache.calcite.rel.logical.LogicalTableFunctionScan}.
*/
-public class PushFilterPastTableFunctionRule extends RelOptRule {
- public static final PushFilterPastTableFunctionRule INSTANCE =
- new PushFilterPastTableFunctionRule();
+public class FilterTableFunctionTransposeRule extends RelOptRule {
+ public static final FilterTableFunctionTransposeRule INSTANCE =
+ new FilterTableFunctionTransposeRule();
//~ Constructors -----------------------------------------------------------
/**
- * Creates a PushFilterPastTableFunctionRule.
+ * Creates a FilterTableFunctionTransposeRule.
*/
- private PushFilterPastTableFunctionRule() {
+ private FilterTableFunctionTransposeRule() {
super(
- operand(
- FilterRel.class,
- operand(TableFunctionRel.class, any())));
+ operand(LogicalFilter.class,
+ operand(LogicalTableFunctionScan.class, any())));
}
//~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- FilterRel filterRel = call.rel(0);
- TableFunctionRel funcRel = call.rel(1);
+ LogicalFilter filter = call.rel(0);
+ LogicalTableFunctionScan funcRel = call.rel(1);
Set<RelColumnMapping> columnMappings = funcRel.getColumnMappings();
- if ((columnMappings == null) || (columnMappings.isEmpty())) {
- // No column mapping information, so no pushdown
+ if (columnMappings == null || columnMappings.isEmpty()) {
+ // No column mapping information, so no push-down
// possible.
return;
}
@@ -78,11 +86,11 @@ public class PushFilterPastTableFunctionRule extends RelOptRule {
}
final List<RelNode> newFuncInputs = new ArrayList<RelNode>();
final RelOptCluster cluster = funcRel.getCluster();
- final RexNode condition = filterRel.getCondition();
+ final RexNode condition = filter.getCondition();
// create filters on top of each func input, modifying the filter
// condition to reference the child instead
- RexBuilder rexBuilder = filterRel.getCluster().getRexBuilder();
+ RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
List<RelDataTypeField> origFields = funcRel.getRowType().getFieldList();
// TODO: these need to be non-zero once we
// support arbitrary mappings
@@ -96,12 +104,12 @@ public class PushFilterPastTableFunctionRule extends RelOptRule {
funcInput.getRowType().getFieldList(),
adjustments));
newFuncInputs.add(
- new FilterRel(cluster, funcInput, newCondition));
+ new LogicalFilter(cluster, funcInput, newCondition));
}
// create a new UDX whose children are the filters created above
- TableFunctionRel newFuncRel =
- new TableFunctionRel(
+ LogicalTableFunctionScan newFuncRel =
+ new LogicalTableFunctionScan(
cluster,
newFuncInputs,
funcRel.getCall(),
@@ -111,4 +119,4 @@ public class PushFilterPastTableFunctionRule extends RelOptRule {
}
}
-// End PushFilterPastTableFunctionRule.java
+// End FilterTableFunctionTransposeRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/FilterTableRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/FilterTableRule.java b/core/src/main/java/org/apache/calcite/rel/rules/FilterTableRule.java
index c168ef9..f135dca 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/FilterTableRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/FilterTableRule.java
@@ -14,41 +14,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
-
-import java.util.List;
-
-import org.eigenbase.rel.FilterRelBase;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.rel.TableAccessRelBase;
-import org.eigenbase.relopt.RelOptRule;
-import org.eigenbase.relopt.RelOptRuleCall;
-import org.eigenbase.relopt.RelOptTable;
-import org.eigenbase.relopt.RelOptUtil;
-import org.eigenbase.rex.*;
-
-import net.hydromatic.linq4j.Enumerable;
-
-import net.hydromatic.optiq.DataContext;
-import net.hydromatic.optiq.FilterableTable;
-import net.hydromatic.optiq.ProjectableFilterableTable;
-import net.hydromatic.optiq.rules.java.EnumerableRel;
-import net.hydromatic.optiq.rules.java.JavaRules;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.enumerable.EnumerableInterpreter;
+import org.apache.calcite.adapter.enumerable.EnumerableRel;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.TableScan;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.schema.FilterableTable;
+import org.apache.calcite.schema.ProjectableFilterableTable;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
-import static org.eigenbase.util.Static.RESOURCE;
+import java.util.List;
+
+import static org.apache.calcite.util.Static.RESOURCE;
/**
* Planner rule that pushes a filter into a scan of a {@link FilterableTable}
- * or {@link net.hydromatic.optiq.ProjectableFilterableTable}.
+ * or {@link org.apache.calcite.schema.ProjectableFilterableTable}.
*/
public class FilterTableRule extends RelOptRule {
- private static final Predicate<TableAccessRelBase> PREDICATE =
- new Predicate<TableAccessRelBase>() {
- public boolean apply(TableAccessRelBase scan) {
+ private static final Predicate<TableScan> PREDICATE =
+ new Predicate<TableScan>() {
+ public boolean apply(TableScan scan) {
// We can only push filters into a FilterableTable or
// ProjectableFilterableTable.
final RelOptTable table = scan.getTable();
@@ -64,18 +62,18 @@ public class FilterTableRule extends RelOptRule {
/** Creates a FilterTableRule. */
private FilterTableRule() {
super(
- operand(FilterRelBase.class,
- operand(JavaRules.EnumerableInterpreterRel.class,
- operand(TableAccessRelBase.class, null, PREDICATE, none()))));
+ operand(Filter.class,
+ operand(EnumerableInterpreter.class,
+ operand(TableScan.class, null, PREDICATE, none()))));
}
//~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- final FilterRelBase filter = call.rel(0);
- final JavaRules.EnumerableInterpreterRel interpreter = call.rel(1);
- final TableAccessRelBase scan = call.rel(2);
+ final Filter filter = call.rel(0);
+ final EnumerableInterpreter interpreter = call.rel(1);
+ final TableScan scan = call.rel(2);
final FilterableTable filterableTable =
scan.getTable().unwrap(FilterableTable.class);
final ProjectableFilterableTable projectableFilterableTable =
@@ -95,10 +93,10 @@ public class FilterTableRule extends RelOptRule {
// It's worth using the ProjectableFilterableTable interface even if it
// refused all filters.
final RelNode newFilter =
- RelOptUtil.createFilter(interpreter.getChild(),
+ RelOptUtil.createFilter(interpreter.getInput(),
filterSplit.acceptedFilters, EnumerableRel.FILTER_FACTORY);
final RelNode newInterpreter =
- new JavaRules.EnumerableInterpreterRel(interpreter.getCluster(),
+ new EnumerableInterpreter(interpreter.getCluster(),
interpreter.getTraitSet(), newFilter, 0.15d);
final RelNode residue =
RelOptUtil.createFilter(newInterpreter, filterSplit.rejectedFilters);
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/FilterToCalcRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/FilterToCalcRule.java b/core/src/main/java/org/apache/calcite/rel/rules/FilterToCalcRule.java
index d3aaeef..6df80d2 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/FilterToCalcRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/FilterToCalcRule.java
@@ -14,23 +14,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalCalc;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
import com.google.common.collect.ImmutableList;
/**
- * Planner rule which converts a {@link FilterRel} to a {@link CalcRel}.
+ * Planner rule which converts a
+ * {@link org.apache.calcite.rel.logical.LogicalFilter} to a
+ * {@link org.apache.calcite.rel.logical.LogicalCalc}.
*
- * <p>The rule does <em>NOT</em> fire if the child is a {@link FilterRel} or a
- * {@link ProjectRel} (we assume they they will be converted using {@link
- * FilterToCalcRule} or {@link ProjectToCalcRule}) or a {@link CalcRel}. This
- * {@link FilterRel} will eventually be converted by {@link
- * MergeFilterOntoCalcRule}.
+ * <p>The rule does <em>NOT</em> fire if the child is a
+ * {@link org.apache.calcite.rel.logical.LogicalFilter} or a
+ * {@link org.apache.calcite.rel.logical.LogicalProject} (we assume they they
+ * will be converted using {@link FilterToCalcRule} or
+ * {@link ProjectToCalcRule}) or a
+ * {@link org.apache.calcite.rel.logical.LogicalCalc}. This
+ * {@link org.apache.calcite.rel.logical.LogicalFilter} will eventually be
+ * converted by {@link FilterCalcMergeRule}.
*/
public class FilterToCalcRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
@@ -40,14 +51,14 @@ public class FilterToCalcRule extends RelOptRule {
//~ Constructors -----------------------------------------------------------
private FilterToCalcRule() {
- super(operand(FilterRel.class, any()));
+ super(operand(LogicalFilter.class, any()));
}
//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
- final FilterRel filter = call.rel(0);
- final RelNode rel = filter.getChild();
+ final LogicalFilter filter = call.rel(0);
+ final RelNode rel = filter.getInput();
// Create a program containing a filter.
final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
@@ -58,8 +69,8 @@ public class FilterToCalcRule extends RelOptRule {
programBuilder.addCondition(filter.getCondition());
final RexProgram program = programBuilder.getProgram();
- final CalcRel calc =
- new CalcRel(
+ final LogicalCalc calc =
+ new LogicalCalc(
filter.getCluster(),
filter.getTraitSet(),
rel,
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/JoinAddRedundantSemiJoinRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinAddRedundantSemiJoinRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinAddRedundantSemiJoinRule.java
index c0caa65..2940ac4 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinAddRedundantSemiJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinAddRedundantSemiJoinRule.java
@@ -14,36 +14,44 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
+import org.apache.calcite.plan.Convention;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinInfo;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.core.SemiJoin;
+import org.apache.calcite.rel.logical.LogicalJoin;
/**
* Rule to add a semi-join into a join. Transformation is as follows:
*
- * <p>JoinRel(X, Y) → JoinRel(SemiJoinRel(X, Y), Y)
+ * <p>LogicalJoin(X, Y) → LogicalJoin(SemiJoin(X, Y), Y)
*
* <p>The constructor is parameterized to allow any sub-class of
- * {@link JoinRelBase}, not just {@link JoinRel}.</p>
+ * {@link org.apache.calcite.rel.core.Join}, not just
+ * {@link org.apache.calcite.rel.logical.LogicalJoin}.
*/
-public class AddRedundantSemiJoinRule extends RelOptRule {
- public static final AddRedundantSemiJoinRule INSTANCE =
- new AddRedundantSemiJoinRule(JoinRel.class);
+public class JoinAddRedundantSemiJoinRule extends RelOptRule {
+ public static final JoinAddRedundantSemiJoinRule INSTANCE =
+ new JoinAddRedundantSemiJoinRule(LogicalJoin.class);
//~ Constructors -----------------------------------------------------------
/**
- * Creates an AddRedundantSemiJoinRule.
+ * Creates an JoinAddRedundantSemiJoinRule.
*/
- private AddRedundantSemiJoinRule(Class<? extends JoinRelBase> clazz) {
+ private JoinAddRedundantSemiJoinRule(Class<? extends Join> clazz) {
super(operand(clazz, any()));
}
//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
- JoinRelBase origJoinRel = call.rel(0);
+ Join origJoinRel = call.rel(0);
if (origJoinRel.isSemiJoinDone()) {
return;
}
@@ -60,7 +68,7 @@ public class AddRedundantSemiJoinRule extends RelOptRule {
}
RelNode semiJoin =
- new SemiJoinRel(
+ new SemiJoin(
origJoinRel.getCluster(),
origJoinRel.getCluster().traitSetOf(Convention.NONE),
origJoinRel.getLeft(),
@@ -82,4 +90,4 @@ public class AddRedundantSemiJoinRule extends RelOptRule {
}
}
-// End AddRedundantSemiJoinRule.java
+// End JoinAddRedundantSemiJoinRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/JoinAssociateRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinAssociateRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinAssociateRule.java
index 0c17984..6a38a9a 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinAssociateRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinAssociateRule.java
@@ -14,60 +14,61 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.volcano.RelSubset;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexPermuteInputsShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.util.BitSets;
+import org.apache.calcite.util.mapping.Mappings;
+
+import com.google.common.collect.Lists;
import java.util.BitSet;
import java.util.List;
-import org.eigenbase.rel.JoinRelBase;
-import org.eigenbase.rel.JoinRelType;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.RelOptCluster;
-import org.eigenbase.relopt.RelOptRule;
-import org.eigenbase.relopt.RelOptRuleCall;
-import org.eigenbase.relopt.volcano.RelSubset;
-import org.eigenbase.rex.RexBuilder;
-import org.eigenbase.rex.RexNode;
-import org.eigenbase.rex.RexPermuteInputsShuttle;
-import org.eigenbase.rex.RexUtil;
-import org.eigenbase.util.mapping.Mappings;
-
-import net.hydromatic.optiq.util.BitSets;
-
-import com.google.common.collect.Lists;
-
/**
- * Planner rule that changes a join based on the commutativity rule.
+ * Planner rule that changes a join based on the associativity rule.
*
* <p>((a JOIN b) JOIN c) → (a JOIN (b JOIN c))</p>
*
* <p>We do not need a rule to convert (a JOIN (b JOIN c)) →
* ((a JOIN b) JOIN c) because we have
- * {@link org.eigenbase.rel.rules.SwapJoinRule}.
+ * {@link JoinCommuteRule}.
+ *
+ * @see JoinCommuteRule
*/
-public class CommutativeJoinRule extends RelOptRule {
+public class JoinAssociateRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
/** The singleton. */
- public static final CommutativeJoinRule INSTANCE = new CommutativeJoinRule();
+ public static final JoinAssociateRule INSTANCE = new JoinAssociateRule();
//~ Constructors -----------------------------------------------------------
/**
- * Creates an CommutativeJoinRule.
+ * Creates a JoinAssociateRule.
*/
- private CommutativeJoinRule() {
+ private JoinAssociateRule() {
super(
- operand(JoinRelBase.class,
- operand(JoinRelBase.class, any()),
+ operand(Join.class,
+ operand(Join.class, any()),
operand(RelSubset.class, any())));
}
//~ Methods ----------------------------------------------------------------
public void onMatch(final RelOptRuleCall call) {
- final JoinRelBase topJoin = call.rel(0);
- final JoinRelBase bottomJoin = call.rel(1);
+ final Join topJoin = call.rel(0);
+ final Join bottomJoin = call.rel(1);
final RelNode relA = bottomJoin.getLeft();
final RelNode relB = bottomJoin.getRight();
final RelSubset relC = call.rel(2);
@@ -116,8 +117,8 @@ public class CommutativeJoinRule extends RelOptRule {
// condition can be pushed down if it does not use columns from A.
final List<RexNode> top = Lists.newArrayList();
final List<RexNode> bottom = Lists.newArrayList();
- PushJoinThroughJoinRule.split(topJoin.getCondition(), aBitSet, top, bottom);
- PushJoinThroughJoinRule.split(bottomJoin.getCondition(), aBitSet, top,
+ JoinPushThroughJoinRule.split(topJoin.getCondition(), aBitSet, top, bottom);
+ JoinPushThroughJoinRule.split(bottomJoin.getCondition(), aBitSet, top,
bottom);
// Mapping for moving conditions from topJoin or bottomJoin to
@@ -135,7 +136,7 @@ public class CommutativeJoinRule extends RelOptRule {
RexNode newBottomCondition =
RexUtil.composeConjunction(rexBuilder, newBottomList, false);
- final JoinRelBase newBottomJoin =
+ final Join newBottomJoin =
bottomJoin.copy(bottomJoin.getTraitSet(), newBottomCondition, relB,
relC, JoinRelType.INNER, false);
@@ -143,7 +144,7 @@ public class CommutativeJoinRule extends RelOptRule {
// Field ordinals do not need to be changed.
RexNode newTopCondition =
RexUtil.composeConjunction(rexBuilder, top, false);
- final JoinRelBase newTopJoin =
+ final Join newTopJoin =
topJoin.copy(topJoin.getTraitSet(), newTopCondition, relA,
newBottomJoin, JoinRelType.INNER, false);
@@ -151,4 +152,4 @@ public class CommutativeJoinRule extends RelOptRule {
}
}
-// End CommutativeJoinRule.java
+// End JoinAssociateRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/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 5d353e1..b90ea97 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
@@ -14,41 +14,56 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
-
-import java.util.*;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.rel.RelFactories.ProjectFactory;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.util.*;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rel.core.RelFactories.ProjectFactory;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.util.Util;
import com.google.common.collect.ImmutableList;
+import java.util.List;
+
/**
- * <code>SwapJoinRule</code> permutes the inputs to a join. Outer joins cannot
- * be permuted.
+ * Planner rule that permutes the inputs to a
+ * {@link org.apache.calcite.rel.core.Join}.
+ *
+ * <p>Outer joins cannot be permuted.
+ *
+ * <p>To preserve the order of columns in the output row, the rule adds a
+ * {@link org.apache.calcite.rel.core.Project}.
*/
-public class SwapJoinRule extends RelOptRule {
+public class JoinCommuteRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
/** The singleton. */
- public static final SwapJoinRule INSTANCE = new SwapJoinRule();
+ public static final JoinCommuteRule INSTANCE = new JoinCommuteRule();
private final ProjectFactory projectFactory;
//~ Constructors -----------------------------------------------------------
/**
- * Creates a SwapJoinRule.
+ * Creates a JoinCommuteRule.
*/
- private SwapJoinRule() {
- this(JoinRel.class, RelFactories.DEFAULT_PROJECT_FACTORY);
+ private JoinCommuteRule() {
+ this(LogicalJoin.class, RelFactories.DEFAULT_PROJECT_FACTORY);
}
- public SwapJoinRule(Class<? extends JoinRelBase> clazz,
+ public JoinCommuteRule(Class<? extends Join> clazz,
ProjectFactory projectFactory) {
super(operand(clazz, any()));
this.projectFactory = projectFactory;
@@ -61,7 +76,7 @@ public class SwapJoinRule extends RelOptRule {
* modify <code>join</code>. Returns null if the join cannot be swapped (for
* example, because it is an outer join).
*/
- public static RelNode swap(JoinRelBase join) {
+ public static RelNode swap(Join join) {
return swap(join, false);
}
@@ -70,7 +85,7 @@ public class SwapJoinRule extends RelOptRule {
* @param swapOuterJoins whether outer joins should be swapped
* @return swapped join if swapping possible; else null
*/
- public static RelNode swap(JoinRelBase join, boolean swapOuterJoins) {
+ public static RelNode swap(Join join, boolean swapOuterJoins) {
final JoinRelType joinType = join.getJoinType();
if (!swapOuterJoins && joinType != JoinRelType.INNER) {
return null;
@@ -88,7 +103,7 @@ public class SwapJoinRule extends RelOptRule {
// join, and one for the swapped join, and no more. This
// doesn't prevent us from seeing any new combinations assuming
// that the planner tries the desired order (semijoins after swaps).
- JoinRelBase newJoin =
+ Join newJoin =
join.copy(join.getTraitSet(), condition, join.getRight(),
join.getLeft(), joinType.swap(), join.isSemiJoinDone());
final List<RexNode> exps =
@@ -101,7 +116,7 @@ public class SwapJoinRule extends RelOptRule {
}
public void onMatch(final RelOptRuleCall call) {
- JoinRelBase join = call.rel(0);
+ Join join = call.rel(0);
if (!join.getSystemFieldList().isEmpty()) {
// FIXME Enable this rule for joins with system fields
@@ -115,10 +130,10 @@ public class SwapJoinRule extends RelOptRule {
// The result is either a Project or, if the project is trivial, a
// raw Join.
- final JoinRelBase newJoin =
- swapped instanceof JoinRelBase
- ? (JoinRelBase) swapped
- : (JoinRelBase) swapped.getInput(0);
+ final Join newJoin =
+ swapped instanceof Join
+ ? (Join) swapped
+ : (Join) swapped.getInput(0);
call.transformTo(swapped);
@@ -187,8 +202,7 @@ public class SwapJoinRule extends RelOptRule {
rightFields.get(index).getType(),
index);
}
- throw Util.newInternal(
- "Bad field offset: index="
+ throw Util.newInternal("Bad field offset: index="
+ var.getIndex()
+ ", leftFieldCount=" + leftFields.size()
+ ", rightFieldCount=" + rightFields.size());
@@ -199,4 +213,4 @@ public class SwapJoinRule extends RelOptRule {
}
}
-// End SwapJoinRule.java
+// End JoinCommuteRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/JoinExtractFilterRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinExtractFilterRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinExtractFilterRule.java
index 39563d3..724b318 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinExtractFilterRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinExtractFilterRule.java
@@ -14,42 +14,50 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.logical.LogicalJoin;
/**
- * Rule to convert an {@link JoinRel inner join} to a {@link FilterRel filter}
- * on top of a {@link JoinRel cartesian inner join}.
+ * Rule to convert an
+ * {@link org.apache.calcite.rel.logical.LogicalJoin inner join} to a
+ * {@link org.apache.calcite.rel.logical.LogicalFilter filter} on top of a
+ * {@link org.apache.calcite.rel.logical.LogicalJoin cartesian inner join}.
*
* <p>One benefit of this transformation is that after it, the join condition
* can be combined with conditions and expressions above the join. It also makes
* the <code>FennelCartesianJoinRule</code> applicable.
*
* <p>The constructor is parameterized to allow any sub-class of
- * {@link JoinRelBase}, not just {@link JoinRel}.</p>
+ * {@link org.apache.calcite.rel.core.Join}, not just
+ * {@link org.apache.calcite.rel.logical.LogicalJoin}.</p>
*/
-public final class ExtractJoinFilterRule extends RelOptRule {
+public final class JoinExtractFilterRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
/** The singleton. */
- public static final ExtractJoinFilterRule INSTANCE =
- new ExtractJoinFilterRule(JoinRel.class);
+ public static final JoinExtractFilterRule INSTANCE =
+ new JoinExtractFilterRule(LogicalJoin.class);
//~ Constructors -----------------------------------------------------------
/**
- * Creates an ExtractJoinFilterRule.
+ * Creates an JoinExtractFilterRule.
*/
- public ExtractJoinFilterRule(Class<? extends JoinRelBase> clazz) {
+ public JoinExtractFilterRule(Class<? extends Join> clazz) {
super(operand(clazz, any()));
}
//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
- final JoinRelBase join = call.rel(0);
+ final Join join = call.rel(0);
if (join.getJoinType() != JoinRelType.INNER) {
return;
@@ -64,7 +72,7 @@ public final class ExtractJoinFilterRule extends RelOptRule {
return;
}
- // NOTE jvs 14-Mar-2006: See SwapJoinRule for why we
+ // NOTE jvs 14-Mar-2006: See JoinCommuteRule for why we
// preserve attribute semiJoinDone here.
RelNode cartesianJoinRel =
@@ -85,4 +93,4 @@ public final class ExtractJoinFilterRule extends RelOptRule {
}
}
-// End ExtractJoinFilterRule.java
+// End JoinExtractFilterRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/JoinProjectTransposeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinProjectTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinProjectTransposeRule.java
index 9af4990..b266e68 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinProjectTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinProjectTransposeRule.java
@@ -14,60 +14,77 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
-import java.util.*;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rel.core.RelFactories.ProjectFactory;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexLocalRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.util.Pair;
-import org.eigenbase.rel.*;
-import org.eigenbase.rel.RelFactories.ProjectFactory;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.util.Pair;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
/**
- * PullUpProjectsAboveJoinRule implements the rule for pulling {@link
- * ProjectRel}s beneath a {@link JoinRelBase} above the {@link JoinRelBase}. Projections
- * are pulled up if the {@link ProjectRel} doesn't originate from a null
- * generating input in an outer join.
+ * Planner rule that matches a
+ * {@link org.apache.calcite.rel.core.Join} one of whose inputs is a
+ * {@link org.apache.calcite.rel.logical.LogicalProject}, and
+ * pulls the project up.
+ *
+ * <p>Projections are pulled up if the
+ * {@link org.apache.calcite.rel.logical.LogicalProject} doesn't originate from
+ * a null generating input in an outer join.
*/
-public class PullUpProjectsAboveJoinRule extends RelOptRule {
+public class JoinProjectTransposeRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
- public static final PullUpProjectsAboveJoinRule BOTH_PROJECT =
- new PullUpProjectsAboveJoinRule(
- operand(
- JoinRel.class,
- operand(ProjectRel.class, any()),
- operand(ProjectRel.class, any())),
- "PullUpProjectsAboveJoinRule: with two ProjectRel children");
+ public static final JoinProjectTransposeRule BOTH_PROJECT =
+ new JoinProjectTransposeRule(
+ operand(LogicalJoin.class,
+ operand(LogicalProject.class, any()),
+ operand(LogicalProject.class, any())),
+ "JoinProjectTransposeRule: with two LogicalProject children");
- public static final PullUpProjectsAboveJoinRule LEFT_PROJECT =
- new PullUpProjectsAboveJoinRule(
- operand(
- JoinRel.class,
- some(
- operand(ProjectRel.class, any()))),
- "PullUpProjectsAboveJoinRule: with ProjectRel on left");
+ public static final JoinProjectTransposeRule LEFT_PROJECT =
+ new JoinProjectTransposeRule(
+ operand(LogicalJoin.class,
+ some(operand(LogicalProject.class, any()))),
+ "JoinProjectTransposeRule: with LogicalProject on left");
- public static final PullUpProjectsAboveJoinRule RIGHT_PROJECT =
- new PullUpProjectsAboveJoinRule(
+ public static final JoinProjectTransposeRule RIGHT_PROJECT =
+ new JoinProjectTransposeRule(
operand(
- JoinRel.class,
+ LogicalJoin.class,
operand(RelNode.class, any()),
- operand(ProjectRel.class, any())),
- "PullUpProjectsAboveJoinRule: with ProjectRel on right");
+ operand(LogicalProject.class, any())),
+ "JoinProjectTransposeRule: with LogicalProject on right");
private final ProjectFactory projectFactory;
//~ Constructors -----------------------------------------------------------
- public PullUpProjectsAboveJoinRule(
+ public JoinProjectTransposeRule(
RelOptRuleOperand operand,
String description) {
this(operand, description, RelFactories.DEFAULT_PROJECT_FACTORY);
}
- public PullUpProjectsAboveJoinRule(
+ public JoinProjectTransposeRule(
RelOptRuleOperand operand,
String description, ProjectFactory pFactory) {
super(operand, description);
@@ -78,11 +95,11 @@ public class PullUpProjectsAboveJoinRule extends RelOptRule {
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- JoinRelBase joinRel = call.rel(0);
+ Join joinRel = call.rel(0);
JoinRelType joinType = joinRel.getJoinType();
- ProjectRelBase leftProj;
- ProjectRelBase rightProj;
+ Project leftProj;
+ Project rightProj;
RelNode leftJoinChild;
RelNode rightJoinChild;
@@ -115,7 +132,7 @@ public class PullUpProjectsAboveJoinRule extends RelOptRule {
// into the bottom RexProgram. Note that the join type is an inner
// join because the inputs haven't actually been joined yet.
RelDataType joinChildrenRowType =
- JoinRelBase.deriveJoinRowType(
+ Join.deriveJoinRowType(
leftJoinChild.getRowType(),
rightJoinChild.getRowType(),
JoinRelType.INNER,
@@ -182,13 +199,13 @@ public class PullUpProjectsAboveJoinRule extends RelOptRule {
bottomProgram,
rexBuilder);
- // expand out the join condition and construct a new JoinRel that
+ // expand out the join condition and construct a new LogicalJoin that
// directly references the join children without the intervening
// ProjectRels
RexNode newCondition =
mergedProgram.expandLocalRef(
mergedProgram.getCondition());
- JoinRelBase newJoinRel =
+ Join newJoinRel =
joinRel.copy(joinRel.getTraitSet(), newCondition,
leftJoinChild, rightJoinChild, joinRel.getJoinType(),
joinRel.isSemiJoinDone());
@@ -227,7 +244,7 @@ public class PullUpProjectsAboveJoinRule extends RelOptRule {
* @return true if the rule was invoked with a left project child
*/
protected boolean hasLeftChild(RelOptRuleCall call) {
- return call.rel(1) instanceof ProjectRelBase;
+ return call.rel(1) instanceof Project;
}
/**
@@ -240,27 +257,27 @@ public class PullUpProjectsAboveJoinRule extends RelOptRule {
/**
* @param call RelOptRuleCall
- * @return ProjectRel corresponding to the right child
+ * @return LogicalProject corresponding to the right child
*/
- protected ProjectRelBase getRightChild(RelOptRuleCall call) {
+ protected Project getRightChild(RelOptRuleCall call) {
return call.rel(2);
}
/**
* Returns the child of the project that will be used as input into the new
- * JoinRel once the projects are pulled above the JoinRel.
+ * LogicalJoin once the projects are pulled above the LogicalJoin.
*
* @param call RelOptRuleCall
* @param project project RelNode
* @param leftChild true if the project corresponds to the left projection
* @return child of the project that will be used as input into the new
- * JoinRel once the projects are pulled above the JoinRel
+ * LogicalJoin once the projects are pulled above the LogicalJoin
*/
protected RelNode getProjectChild(
RelOptRuleCall call,
- ProjectRelBase project,
+ Project project,
boolean leftChild) {
- return project.getChild();
+ return project.getInput();
}
/**
@@ -278,7 +295,7 @@ public class PullUpProjectsAboveJoinRule extends RelOptRule {
* @param projects Projection expressions & names to be created
*/
private void createProjectExprs(
- ProjectRelBase projRel,
+ Project projRel,
RelNode joinChild,
int adjustmentAmount,
RexBuilder rexBuilder,
@@ -322,4 +339,4 @@ public class PullUpProjectsAboveJoinRule extends RelOptRule {
}
}
-// End PullUpProjectsAboveJoinRule.java
+// End JoinProjectTransposeRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/JoinPushThroughJoinRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinPushThroughJoinRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinPushThroughJoinRule.java
index 76b7f2e..8e024aa 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinPushThroughJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinPushThroughJoinRule.java
@@ -14,17 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
-
-import java.util.*;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.rel.RelFactories.ProjectFactory;
-import org.eigenbase.relopt.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.util.mapping.Mappings;
-
-import net.hydromatic.optiq.util.BitSets;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rel.core.RelFactories.ProjectFactory;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexPermuteInputsShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.util.BitSets;
+import org.apache.calcite.util.mapping.Mappings;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
/**
* Rule that pushes the right input of a join into through the left input of
@@ -49,19 +60,19 @@ import net.hydromatic.optiq.util.BitSets;
* <p>Before the rule, one join has two conditions and the other has none
* ({@code ON TRUE}). After the rule, each join has one condition.</p>
*/
-public class PushJoinThroughJoinRule extends RelOptRule {
+public class JoinPushThroughJoinRule extends RelOptRule {
/** Instance of the rule that works on logical joins only, and pushes to the
* right. */
public static final RelOptRule RIGHT =
- new PushJoinThroughJoinRule(
- "PushJoinThroughJoinRule:right", true, JoinRel.class,
+ new JoinPushThroughJoinRule(
+ "JoinPushThroughJoinRule:right", true, LogicalJoin.class,
RelFactories.DEFAULT_PROJECT_FACTORY);
/** Instance of the rule that works on logical joins only, and pushes to the
* left. */
public static final RelOptRule LEFT =
- new PushJoinThroughJoinRule(
- "PushJoinThroughJoinRule:left", false, JoinRel.class,
+ new JoinPushThroughJoinRule(
+ "JoinPushThroughJoinRule:left", false, LogicalJoin.class,
RelFactories.DEFAULT_PROJECT_FACTORY);
private final boolean right;
@@ -69,13 +80,12 @@ public class PushJoinThroughJoinRule extends RelOptRule {
private final ProjectFactory projectFactory;
/**
- * Creates a PushJoinThroughJoinRule.
+ * Creates a JoinPushThroughJoinRule.
*/
- public PushJoinThroughJoinRule(String description, boolean right,
- Class<? extends JoinRelBase> clazz, ProjectFactory projectFactory) {
+ public JoinPushThroughJoinRule(String description, boolean right,
+ Class<? extends Join> clazz, ProjectFactory projectFactory) {
super(
- operand(
- clazz,
+ operand(clazz,
operand(clazz, any()),
operand(RelNode.class, any())),
description);
@@ -83,8 +93,7 @@ public class PushJoinThroughJoinRule extends RelOptRule {
this.projectFactory = projectFactory;
}
- @Override
- public void onMatch(RelOptRuleCall call) {
+ @Override public void onMatch(RelOptRuleCall call) {
if (right) {
onMatchRight(call);
} else {
@@ -93,8 +102,8 @@ public class PushJoinThroughJoinRule extends RelOptRule {
}
private void onMatchRight(RelOptRuleCall call) {
- final JoinRelBase topJoin = call.rel(0);
- final JoinRelBase bottomJoin = call.rel(1);
+ final Join topJoin = call.rel(0);
+ final Join bottomJoin = call.rel(1);
final RelNode relC = call.rel(2);
final RelNode relA = bottomJoin.getLeft();
final RelNode relB = bottomJoin.getRight();
@@ -164,7 +173,7 @@ public class PushJoinThroughJoinRule extends RelOptRule {
final RexBuilder rexBuilder = cluster.getRexBuilder();
RexNode newBottomCondition =
RexUtil.composeConjunction(rexBuilder, newBottomList, false);
- final JoinRelBase newBottomJoin =
+ final Join newBottomJoin =
bottomJoin.copy(bottomJoin.getTraitSet(), newBottomCondition, relA,
relC, bottomJoin.getJoinType(), bottomJoin.isSemiJoinDone());
@@ -184,7 +193,7 @@ public class PushJoinThroughJoinRule extends RelOptRule {
RexNode newTopCondition =
RexUtil.composeConjunction(rexBuilder, newTopList, false);
@SuppressWarnings("SuspiciousNameCombination")
- final JoinRelBase newTopJoin =
+ final Join newTopJoin =
topJoin.copy(topJoin.getTraitSet(), newTopCondition, newBottomJoin,
relB, topJoin.getJoinType(), topJoin.isSemiJoinDone());
@@ -200,8 +209,8 @@ public class PushJoinThroughJoinRule extends RelOptRule {
* of the two lower siblings, rather than the right.
*/
private void onMatchLeft(RelOptRuleCall call) {
- final JoinRelBase topJoin = call.rel(0);
- final JoinRelBase bottomJoin = call.rel(1);
+ final Join topJoin = call.rel(0);
+ final Join bottomJoin = call.rel(1);
final RelNode relC = call.rel(2);
final RelNode relA = bottomJoin.getLeft();
final RelNode relB = bottomJoin.getRight();
@@ -272,7 +281,7 @@ public class PushJoinThroughJoinRule extends RelOptRule {
final RexBuilder rexBuilder = cluster.getRexBuilder();
RexNode newBottomCondition =
RexUtil.composeConjunction(rexBuilder, newBottomList, false);
- final JoinRelBase newBottomJoin =
+ final Join newBottomJoin =
bottomJoin.copy(bottomJoin.getTraitSet(), newBottomCondition, relC,
relB, bottomJoin.getJoinType(), bottomJoin.isSemiJoinDone());
@@ -292,7 +301,7 @@ public class PushJoinThroughJoinRule extends RelOptRule {
RexNode newTopCondition =
RexUtil.composeConjunction(rexBuilder, newTopList, false);
@SuppressWarnings("SuspiciousNameCombination")
- final JoinRelBase newTopJoin =
+ final Join newTopJoin =
topJoin.copy(topJoin.getTraitSet(), newTopCondition, newBottomJoin,
relA, topJoin.getJoinType(), topJoin.isSemiJoinDone());
@@ -322,4 +331,4 @@ public class PushJoinThroughJoinRule extends RelOptRule {
}
}
-// End PushJoinThroughJoinRule.java
+// End JoinPushThroughJoinRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/JoinPushTransitivePredicatesRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinPushTransitivePredicatesRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinPushTransitivePredicatesRule.java
index ab08289..3b7056d 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinPushTransitivePredicatesRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinPushTransitivePredicatesRule.java
@@ -14,42 +14,45 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
-import org.eigenbase.rel.JoinRelBase;
-import org.eigenbase.rel.RelFactories;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.rel.metadata.RelMetadataQuery;
-import org.eigenbase.relopt.RelOptPredicateList;
-import org.eigenbase.relopt.RelOptRule;
-import org.eigenbase.relopt.RelOptRuleCall;
-import org.eigenbase.rex.RexBuilder;
-import org.eigenbase.rex.RexUtil;
+import org.apache.calcite.plan.RelOptPredicateList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rel.metadata.RelMetadataQuery;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexUtil;
/**
- * A Rule to apply inferred predicates from
- * {@link org.eigenbase.rel.metadata.RelMdPredicates}.
+ * Planner rule that infers predicates from on a
+ * {@link org.apache.calcite.rel.core.Join} and creates
+ * {@link org.apache.calcite.rel.core.Filter}s if those predicates can be pushed
+ * to its inputs.
*
- * <p>Predicates returned in {@link org.eigenbase.relopt.RelOptPredicateList}
- * are applied appropriately.
+ * <p>Uses {@link org.apache.calcite.rel.metadata.RelMdPredicates} to infer
+ * the predicates,
+ * returns them in a {@link org.apache.calcite.plan.RelOptPredicateList}
+ * and applies them appropriately.
*/
-public class TransitivePredicatesOnJoinRule extends RelOptRule {
+public class JoinPushTransitivePredicatesRule extends RelOptRule {
private final RelFactories.FilterFactory filterFactory;
/** The singleton. */
- public static final TransitivePredicatesOnJoinRule INSTANCE =
- new TransitivePredicatesOnJoinRule(JoinRelBase.class,
+ public static final JoinPushTransitivePredicatesRule INSTANCE =
+ new JoinPushTransitivePredicatesRule(Join.class,
RelFactories.DEFAULT_FILTER_FACTORY);
- public TransitivePredicatesOnJoinRule(Class<? extends JoinRelBase> clazz,
+ public JoinPushTransitivePredicatesRule(Class<? extends Join> clazz,
RelFactories.FilterFactory filterFactory) {
super(operand(clazz, any()));
this.filterFactory = filterFactory;
}
- @Override
- public void onMatch(RelOptRuleCall call) {
- JoinRelBase join = call.rel(0);
+ @Override public void onMatch(RelOptRuleCall call) {
+ Join join = call.rel(0);
RelOptPredicateList preds = RelMetadataQuery.getPulledUpPredicates(join);
if (preds.leftInferredPredicates.isEmpty()
@@ -83,4 +86,4 @@ public class TransitivePredicatesOnJoinRule extends RelOptRule {
}
}
-// End TransitivePredicatesOnJoinRule.java
+// End JoinPushTransitivePredicatesRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/JoinToCorrelatorRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinToCorrelatorRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinToCorrelatorRule.java
index de40ede..219b662 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinToCorrelatorRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinToCorrelatorRule.java
@@ -14,21 +14,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
-import java.util.*;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.sql.fun.*;
-import org.eigenbase.util.*;
-import org.eigenbase.util.mapping.IntPair;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptQuery;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Correlation;
+import org.apache.calcite.rel.core.Correlator;
+import org.apache.calcite.rel.core.JoinInfo;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.util.Util;
+import org.apache.calcite.util.mapping.IntPair;
import com.google.common.collect.Lists;
+import java.util.List;
+
/**
- * Rule which converts a {@link JoinRel} into a {@link CorrelatorRel}, which can
+ * Rule that converts a {@link org.apache.calcite.rel.logical.LogicalJoin}
+ * into a {@link org.apache.calcite.rel.core.Correlator}, which can
* then be implemented using nested loops.
*
* <p>For example,</p>
@@ -36,8 +46,8 @@ import com.google.common.collect.Lists;
* <blockquote><code>select * from emp join dept on emp.deptno =
* dept.deptno</code></blockquote>
*
- * <p>becomes a CorrelatorRel which restarts TableAccessRel("DEPT") for each row
- * read from TableAccessRel("EMP").</p>
+ * <p>becomes a Correlator which restarts LogicalTableScan("DEPT") for each
+ * row read from LogicalTableScan("EMP").</p>
*
* <p>This rule is not applicable if for certain types of outer join. For
* example,</p>
@@ -46,27 +56,27 @@ import com.google.common.collect.Lists;
* dept.deptno</code></blockquote>
*
* <p>would require emitting a NULL emp row if a certain department contained no
- * employees, and CorrelatorRel cannot do that.</p>
+ * employees, and Correlator cannot do that.</p>
*/
-public class NestedLoopsJoinRule extends RelOptRule {
+public class JoinToCorrelatorRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
- public static final NestedLoopsJoinRule INSTANCE =
- new NestedLoopsJoinRule();
+ public static final JoinToCorrelatorRule INSTANCE =
+ new JoinToCorrelatorRule();
//~ Constructors -----------------------------------------------------------
/**
* Private constructor; use singleton {@link #INSTANCE}.
*/
- private NestedLoopsJoinRule() {
- super(operand(JoinRel.class, any()));
+ private JoinToCorrelatorRule() {
+ super(operand(LogicalJoin.class, any()));
}
//~ Methods ----------------------------------------------------------------
public boolean matches(RelOptRuleCall call) {
- JoinRel join = call.rel(0);
+ LogicalJoin join = call.rel(0);
switch (join.getJoinType()) {
case INNER:
case LEFT:
@@ -81,7 +91,7 @@ public class NestedLoopsJoinRule extends RelOptRule {
public void onMatch(RelOptRuleCall call) {
assert matches(call);
- final JoinRel join = call.rel(0);
+ final LogicalJoin join = call.rel(0);
RelNode right = join.getRight();
final RelNode left = join.getLeft();
final JoinInfo joinInfo = join.analyzeCondition();
@@ -105,7 +115,7 @@ public class NestedLoopsJoinRule extends RelOptRule {
}
final RelNode filteredRight = RelOptUtil.createFilter(right, conditions);
RelNode newRel =
- new CorrelatorRel(
+ new Correlator(
join.getCluster(),
left,
filteredRight,
@@ -116,4 +126,4 @@ public class NestedLoopsJoinRule extends RelOptRule {
}
}
-// End NestedLoopsJoinRule.java
+// End JoinToCorrelatorRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
index ec003b3..082575a 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
@@ -14,40 +14,55 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
-
-import java.util.*;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.util.ImmutableIntList;
-import org.eigenbase.util.Pair;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.rex.RexVisitorImpl;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.calcite.util.Pair;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map;
+
/**
- * Rule to flatten a tree of {@link JoinRel}s into a single {@link MultiJoinRel}
- * with N inputs. An input is not flattened if the input is a null generating
- * input in an outer join, i.e., either input in a full outer join, the right
- * hand side of a left outer join, or the left hand side of a right outer join.
+ * Planner rule to flatten a tree of
+ * {@link org.apache.calcite.rel.logical.LogicalJoin}s
+ * into a single {@link MultiJoin} with N inputs.
+ *
+ * <p>An input is not flattened if
+ * the input is a null generating input in an outer join, i.e., either input in
+ * a full outer join, the right hand side of a left outer join, or the left hand
+ * side of a right outer join.
*
* <p>Join conditions are also pulled up from the inputs into the topmost
- * {@link MultiJoinRel},
+ * {@link MultiJoin},
* unless the input corresponds to a null generating input in an outer join,
*
- * <p>Outer join information is also stored in the {@link MultiJoinRel}. A
+ * <p>Outer join information is also stored in the {@link MultiJoin}. A
* boolean flag indicates if the join is a full outer join, and in the case of
* left and right outer joins, the join type and outer join conditions are
- * stored in arrays in the {@link MultiJoinRel}. This outer join information is
+ * stored in arrays in the {@link MultiJoin}. This outer join information is
* associated with the null generating input in the outer join. So, in the case
* of a a left outer join between A and B, the information is associated with B,
* not A.
*
- * <p>Here are examples of the {@link MultiJoinRel}s constructed after this rule
+ * <p>Here are examples of the {@link MultiJoin}s constructed after this rule
* has been applied on following join trees.
*
* <ul>
@@ -62,35 +77,39 @@ import com.google.common.collect.Maps;
* <li>A FULL JOIN B → MJ[full](A, B)
*
* <li>A LEFT JOIN (B JOIN C) → MJ(A, MJ(B, C))), left outer join on
- * input#1 in the outermost MultiJoinRel
+ * input#1 in the outermost MultiJoin
*
* <li>(A JOIN B) LEFT JOIN C → MJ(A, B, C), left outer join on input#2
*
* <li>(A LEFT JOIN B) JOIN C → MJ(MJ(A, B), C), left outer join on input#1
- * of the inner MultiJoinRel TODO
+ * of the inner MultiJoin TODO
*
* <li>A LEFT JOIN (B FULL JOIN C) → MJ(A, MJ[full](B, C)), left outer join
- * on input#1 in the outermost MultiJoinRel
+ * on input#1 in the outermost MultiJoin
*
* <li>(A LEFT JOIN B) FULL JOIN (C RIGHT JOIN D) →
* MJ[full](MJ(A, B), MJ(C, D)), left outer join on input #1 in the first
- * inner MultiJoinRel and right outer join on input#0 in the second inner
- * MultiJoinRel
+ * inner MultiJoin and right outer join on input#0 in the second inner
+ * MultiJoin
* </ul>
*
* <p>The constructor is parameterized to allow any sub-class of
- * {@link JoinRelBase}, not just {@link JoinRel}.</p>
+ * {@link org.apache.calcite.rel.core.Join}, not just
+ * {@link org.apache.calcite.rel.logical.LogicalJoin}.</p>
+ *
+ * @see org.apache.calcite.rel.rules.FilterMultiJoinMergeRule
+ * @see org.apache.calcite.rel.rules.ProjectMultiJoinMergeRule
*/
-public class ConvertMultiJoinRule extends RelOptRule {
- public static final ConvertMultiJoinRule INSTANCE =
- new ConvertMultiJoinRule(JoinRelBase.class);
+public class JoinToMultiJoinRule extends RelOptRule {
+ public static final JoinToMultiJoinRule INSTANCE =
+ new JoinToMultiJoinRule(LogicalJoin.class);
//~ Constructors -----------------------------------------------------------
/**
- * Creates a ConvertMultiJoinRule.
+ * Creates a JoinToMultiJoinRule.
*/
- public ConvertMultiJoinRule(Class<? extends JoinRelBase> clazz) {
+ public JoinToMultiJoinRule(Class<? extends Join> clazz) {
super(
operand(clazz,
operand(RelNode.class, any()),
@@ -100,12 +119,12 @@ public class ConvertMultiJoinRule extends RelOptRule {
//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
- final JoinRelBase origJoin = call.rel(0);
+ final Join origJoin = call.rel(0);
final RelNode left = call.rel(1);
final RelNode right = call.rel(2);
- // combine the children MultiJoinRel inputs into an array of inputs
- // for the new MultiJoinRel
+ // combine the children MultiJoin inputs into an array of inputs
+ // for the new MultiJoin
final List<BitSet> projFieldsList = Lists.newArrayList();
final List<int[]> joinFieldRefCountsList = Lists.newArrayList();
final List<RelNode> newInputs =
@@ -128,12 +147,12 @@ public class ConvertMultiJoinRule extends RelOptRule {
joinSpecs);
// pull up the join filters from the children MultiJoinRels and
- // combine them with the join filter associated with this JoinRel to
- // form the join filter for the new MultiJoinRel
+ // combine them with the join filter associated with this LogicalJoin to
+ // form the join filter for the new MultiJoin
List<RexNode> newJoinFilters = combineJoinFilters(origJoin, left, right);
// add on the join field reference counts for the join condition
- // associated with this JoinRel
+ // associated with this LogicalJoin
final ImmutableMap<Integer, ImmutableIntList> newJoinFieldRefCountsMap =
addOnJoinFieldRefCounts(newInputs,
origJoin.getRowType().getFieldCount(),
@@ -145,7 +164,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
final RexBuilder rexBuilder = origJoin.getCluster().getRexBuilder();
RelNode multiJoin =
- new MultiJoinRel(
+ new MultiJoin(
origJoin.getCluster(),
newInputs,
RexUtil.composeConjunction(rexBuilder, newJoinFilters, false),
@@ -161,7 +180,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
}
/**
- * Combines the inputs into a JoinRel into an array of inputs.
+ * Combines the inputs into a LogicalJoin into an array of inputs.
*
* @param join original join
* @param left left input into join
@@ -173,7 +192,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
* @return combined left and right inputs in an array
*/
private List<RelNode> combineInputs(
- JoinRelBase join,
+ Join join,
RelNode left,
RelNode right,
List<BitSet> projFieldsList,
@@ -183,7 +202,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
// leave the null generating sides of an outer join intact; don't
// pull up those children inputs into the array we're constructing
if (canCombine(left, join.getJoinType().generatesNullsOnLeft())) {
- final MultiJoinRel leftMultiJoin = (MultiJoinRel) left;
+ final MultiJoin leftMultiJoin = (MultiJoin) left;
for (int i = 0; i < left.getInputs().size(); i++) {
newInputs.add(leftMultiJoin.getInput(i));
projFieldsList.add(leftMultiJoin.getProjFields().get(i));
@@ -198,7 +217,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
}
if (canCombine(right, join.getJoinType().generatesNullsOnRight())) {
- final MultiJoinRel rightMultiJoin = (MultiJoinRel) right;
+ final MultiJoin rightMultiJoin = (MultiJoin) right;
for (int i = 0; i < right.getInputs().size(); i++) {
newInputs.add(rightMultiJoin.getInput(i));
projFieldsList.add(
@@ -231,7 +250,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
* copied
*/
private void combineOuterJoins(
- JoinRelBase joinRel,
+ Join joinRel,
List<RelNode> combinedInputs,
RelNode left,
RelNode right,
@@ -245,7 +264,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
case LEFT:
if (leftCombined) {
copyOuterJoinInfo(
- (MultiJoinRel) left,
+ (MultiJoin) left,
joinSpecs,
0,
null,
@@ -259,7 +278,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
joinSpecs.add(Pair.of(joinType, joinRel.getCondition()));
if (rightCombined) {
copyOuterJoinInfo(
- (MultiJoinRel) right,
+ (MultiJoin) right,
joinSpecs,
left.getRowType().getFieldCount(),
right.getRowType().getFieldList(),
@@ -271,7 +290,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
default:
if (leftCombined) {
copyOuterJoinInfo(
- (MultiJoinRel) left,
+ (MultiJoin) left,
joinSpecs,
0,
null,
@@ -281,7 +300,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
}
if (rightCombined) {
copyOuterJoinInfo(
- (MultiJoinRel) right,
+ (MultiJoin) right,
joinSpecs,
left.getRowType().getFieldCount(),
right.getRowType().getFieldList(),
@@ -293,11 +312,11 @@ public class ConvertMultiJoinRule extends RelOptRule {
}
/**
- * Copies outer join data from a source MultiJoinRel to a new set of arrays.
+ * Copies outer join data from a source MultiJoin to a new set of arrays.
* Also adjusts the conditions to reflect the new position of an input if
* that input ends up being shifted to the right.
*
- * @param multiJoinRel the source MultiJoinRel
+ * @param multiJoin the source MultiJoin
* @param destJoinSpecs the list where the join types and conditions will
* be copied
* @param adjustmentAmount if > 0, the amount the RexInputRefs in the join
@@ -307,15 +326,15 @@ public class ConvertMultiJoinRule extends RelOptRule {
* @param destFields the destination fields that the new join conditions
*/
private void copyOuterJoinInfo(
- MultiJoinRel multiJoinRel,
+ MultiJoin multiJoin,
List<Pair<JoinRelType, RexNode>> destJoinSpecs,
int adjustmentAmount,
List<RelDataTypeField> srcFields,
List<RelDataTypeField> destFields) {
final List<Pair<JoinRelType, RexNode>> srcJoinSpecs =
Pair.zip(
- multiJoinRel.getJoinTypes(),
- multiJoinRel.getOuterJoinConditions());
+ multiJoin.getJoinTypes(),
+ multiJoin.getOuterJoinConditions());
if (adjustmentAmount == 0) {
destJoinSpecs.addAll(srcJoinSpecs);
@@ -334,7 +353,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
? null
: src.right.accept(
new RelOptUtil.RexInputConverter(
- multiJoinRel.getCluster().getRexBuilder(),
+ multiJoin.getCluster().getRexBuilder(),
srcFields, destFields, adjustments))));
}
}
@@ -352,7 +371,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
* @return combined join filters AND-ed together
*/
private List<RexNode> combineJoinFilters(
- JoinRelBase joinRel,
+ Join joinRel,
RelNode left,
RelNode right) {
JoinRelType joinType = joinRel.getJoinType();
@@ -365,12 +384,12 @@ public class ConvertMultiJoinRule extends RelOptRule {
filters.add(joinRel.getCondition());
}
if (canCombine(left, joinType.generatesNullsOnLeft())) {
- filters.add(((MultiJoinRel) left).getJoinFilter());
+ filters.add(((MultiJoin) left).getJoinFilter());
}
// Need to adjust the RexInputs of the right child, since
// those need to shift over to the right
if (canCombine(right, joinType.generatesNullsOnRight())) {
- MultiJoinRel multiJoin = (MultiJoinRel) right;
+ MultiJoin multiJoin = (MultiJoin) right;
filters.add(
shiftRightFilter(joinRel, left, multiJoin,
multiJoin.getJoinFilter()));
@@ -385,30 +404,30 @@ public class ConvertMultiJoinRule extends RelOptRule {
*
* @param input input into a join
* @param nullGenerating true if the input is null generating
- * @return true if the input can be combined into a parent MultiJoinRel
+ * @return true if the input can be combined into a parent MultiJoin
*/
private boolean canCombine(RelNode input, boolean nullGenerating) {
- return input instanceof MultiJoinRel
- && !((MultiJoinRel) input).isFullOuterJoin()
- && !((MultiJoinRel) input).containsOuter()
+ return input instanceof MultiJoin
+ && !((MultiJoin) input).isFullOuterJoin()
+ && !((MultiJoin) input).containsOuter()
&& !nullGenerating;
}
/**
- * Shifts a filter originating from the right child of the JoinRel to the
+ * Shifts a filter originating from the right child of the LogicalJoin to the
* right, to reflect the filter now being applied on the resulting
- * MultiJoinRel.
+ * MultiJoin.
*
- * @param joinRel the original JoinRel
- * @param left the left child of the JoinRel
- * @param right the right child of the JoinRel
+ * @param joinRel the original LogicalJoin
+ * @param left the left child of the LogicalJoin
+ * @param right the right child of the LogicalJoin
* @param rightFilter the filter originating from the right child
* @return the adjusted right filter
*/
private RexNode shiftRightFilter(
- JoinRelBase joinRel,
+ Join joinRel,
RelNode left,
- MultiJoinRel right,
+ MultiJoin right,
RexNode rightFilter) {
if (rightFilter == null) {
return null;
@@ -434,8 +453,8 @@ public class ConvertMultiJoinRule extends RelOptRule {
* Adds on to the existing join condition reference counts the references
* from the new join condition.
*
- * @param multiJoinInputs inputs into the new MultiJoinRel
- * @param nTotalFields total number of fields in the MultiJoinRel
+ * @param multiJoinInputs inputs into the new MultiJoin
+ * @param nTotalFields total number of fields in the MultiJoin
* @param joinCondition the new join condition
* @param origJoinFieldRefCounts existing join condition reference counts
*
@@ -461,7 +480,7 @@ public class ConvertMultiJoinRule extends RelOptRule {
currInput++;
}
- // add on to the counts for each input into the MultiJoinRel the
+ // add on to the counts for each input into the MultiJoin the
// reference counts computed for the current join condition
currInput = -1;
int startField = 0;
@@ -493,25 +512,25 @@ public class ConvertMultiJoinRule extends RelOptRule {
* Combines the post-join filters from the left and right inputs (if they
* are MultiJoinRels) into a single AND'd filter.
*
- * @param joinRel the original JoinRel
- * @param left left child of the JoinRel
- * @param right right child of the JoinRel
+ * @param joinRel the original LogicalJoin
+ * @param left left child of the LogicalJoin
+ * @param right right child of the LogicalJoin
* @return combined post-join filters AND'd together
*/
private List<RexNode> combinePostJoinFilters(
- JoinRelBase joinRel,
+ Join joinRel,
RelNode left,
RelNode right) {
final List<RexNode> filters = Lists.newArrayList();
- if (right instanceof MultiJoinRel) {
- final MultiJoinRel multiRight = (MultiJoinRel) right;
+ if (right instanceof MultiJoin) {
+ final MultiJoin multiRight = (MultiJoin) right;
filters.add(
shiftRightFilter(joinRel, left, multiRight,
multiRight.getPostJoinFilter()));
}
- if (left instanceof MultiJoinRel) {
- filters.add(((MultiJoinRel) left).getPostJoinFilter());
+ if (left instanceof MultiJoin) {
+ filters.add(((MultiJoin) left).getPostJoinFilter());
}
return filters;
@@ -537,4 +556,4 @@ public class ConvertMultiJoinRule extends RelOptRule {
}
}
-// End ConvertMultiJoinRule.java
+// End JoinToMultiJoinRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/JoinUnionTransposeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinUnionTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinUnionTransposeRule.java
index 063f96b..c0fa8af 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinUnionTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinUnionTransposeRule.java
@@ -14,42 +14,50 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
+package org.apache.calcite.rel.rules;
-import java.util.*;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.SetOp;
+import org.apache.calcite.rel.core.Union;
+import org.apache.calcite.rel.logical.LogicalUnion;
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
+import java.util.ArrayList;
+import java.util.List;
/**
- * PushJoinThroughUnionRule implements the rule for pushing a
- * {@link JoinRel} past a non-distinct {@link UnionRel}.
+ * Planner rule that pushes a
+ * {@link org.apache.calcite.rel.logical.LogicalJoin}
+ * past a non-distinct {@link org.apache.calcite.rel.logical.LogicalUnion}.
*/
-public class PushJoinThroughUnionRule extends RelOptRule {
- public static final PushJoinThroughUnionRule LEFT_UNION =
- new PushJoinThroughUnionRule(
- operand(JoinRelBase.class,
- operand(UnionRelBase.class, any()),
+public class JoinUnionTransposeRule extends RelOptRule {
+ public static final JoinUnionTransposeRule LEFT_UNION =
+ new JoinUnionTransposeRule(
+ operand(Join.class,
+ operand(Union.class, any()),
operand(RelNode.class, any())),
"union on left");
- public static final PushJoinThroughUnionRule RIGHT_UNION =
- new PushJoinThroughUnionRule(
- operand(JoinRelBase.class,
+ public static final JoinUnionTransposeRule RIGHT_UNION =
+ new JoinUnionTransposeRule(
+ operand(Join.class,
operand(RelNode.class, any()),
- operand(UnionRelBase.class, any())),
+ operand(Union.class, any())),
"union on right");
- private PushJoinThroughUnionRule(RelOptRuleOperand operand, String id) {
- super(operand, "PushJoinThroughUnionRule: " + id);
+ private JoinUnionTransposeRule(RelOptRuleOperand operand, String id) {
+ super(operand, "JoinUnionTransposeRule: " + id);
}
public void onMatch(RelOptRuleCall call) {
- final JoinRelBase join = call.rel(0);
- final UnionRelBase unionRel;
+ final Join join = call.rel(0);
+ final Union unionRel;
RelNode otherInput;
boolean unionOnLeft;
- if (call.rel(1) instanceof UnionRel) {
+ if (call.rel(1) instanceof LogicalUnion) {
unionRel = call.rel(1);
otherInput = call.rel(2);
unionOnLeft = true;
@@ -97,10 +105,10 @@ public class PushJoinThroughUnionRule extends RelOptRule {
join.getJoinType(),
join.isSemiJoinDone()));
}
- final SetOpRel newUnionRel =
+ final SetOp newUnionRel =
unionRel.copy(unionRel.getTraitSet(), newUnionInputs, true);
call.transformTo(newUnionRel);
}
}
-// End PushJoinThroughUnionRule.java
+// End JoinUnionTransposeRule.java