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:39 UTC
[31/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/ProjectToCalcRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectToCalcRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectToCalcRule.java
index 0e921c8..c6fc5fe 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectToCalcRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectToCalcRule.java
@@ -14,21 +14,30 @@
* 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.LogicalProject;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexProgram;
import com.google.common.collect.ImmutableList;
/**
- * Rule to convert a {@link ProjectRel} to a {@link CalcRel}
+ * Rule to convert a
+ * {@link org.apache.calcite.rel.logical.LogicalProject} to a
+ * {@link org.apache.calcite.rel.logical.LogicalCalc}
*
- * <p>The rule does not fire if the child is a {@link ProjectRel}, {@link
- * FilterRel} or {@link CalcRel}. If it did, then the same {@link CalcRel} would
- * be formed via several transformation paths, which is a waste of effort.</p>
+ * <p>The rule does not fire if the child is a
+ * {@link org.apache.calcite.rel.logical.LogicalProject},
+ * {@link org.apache.calcite.rel.logical.LogicalFilter} or
+ * {@link org.apache.calcite.rel.logical.LogicalCalc}. If it did, then the same
+ * {@link org.apache.calcite.rel.logical.LogicalCalc} would be formed via
+ * several transformation paths, which is a waste of effort.</p>
*
* @see FilterToCalcRule
*/
@@ -40,14 +49,14 @@ public class ProjectToCalcRule extends RelOptRule {
//~ Constructors -----------------------------------------------------------
private ProjectToCalcRule() {
- super(operand(ProjectRel.class, any()));
+ super(operand(LogicalProject.class, any()));
}
//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
- final ProjectRel project = call.rel(0);
- final RelNode child = project.getChild();
+ final LogicalProject project = call.rel(0);
+ final RelNode child = project.getInput();
final RelDataType rowType = project.getRowType();
final RexProgram program =
RexProgram.create(
@@ -56,8 +65,8 @@ public class ProjectToCalcRule extends RelOptRule {
null,
project.getRowType(),
project.getCluster().getRexBuilder());
- final CalcRel calc =
- new CalcRel(
+ final LogicalCalc calc =
+ new LogicalCalc(
project.getCluster(),
project.getTraitSet(),
child,
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java
index ac69d6f..b3a8023 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java
@@ -14,57 +14,85 @@
* 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.reltype.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.util.*;
+import org.apache.calcite.plan.RelOptCluster;
+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.plan.RelTraitSet;
+import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Calc;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.logical.LogicalCalc;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalWindow;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexDynamicParam;
+import org.apache.calcite.rex.RexFieldAccess;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexLocalRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexOver;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.util.Util;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
/**
- * Rule that slices the {@link CalcRel} into sections which contain windowed
- * agg functions and sections which do not.
+ * Planner rule that slices a
+ * {@link org.apache.calcite.rel.core.Project}
+ * into sections which contain windowed
+ * aggregate functions and sections which do not.
*
* <p>The sections which contain windowed agg functions become instances of
- * {@link org.eigenbase.rel.WindowRel}. If the {@link CalcRel} does not contain any
- * windowed agg functions, does nothing.
+ * {@link org.apache.calcite.rel.logical.LogicalWindow}.
+ * If the {@link org.apache.calcite.rel.logical.LogicalCalc} does not contain
+ * any windowed agg functions, does nothing.
+ *
+ * <p>There is also a variant that matches
+ * {@link org.apache.calcite.rel.core.Calc} rather than {@code Project}.
*/
-public abstract class WindowedAggSplitterRule extends RelOptRule {
+public abstract class ProjectToWindowRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
- private static final Predicate<CalcRelBase> PREDICATE =
- new Predicate<CalcRelBase>() {
- public boolean apply(CalcRelBase calc) {
+ private static final Predicate<Calc> PREDICATE =
+ new Predicate<Calc>() {
+ public boolean apply(Calc calc) {
return RexOver.containsOver(calc.getProgram());
}
};
- private static final Predicate<ProjectRelBase> PREDICATE2 =
- new Predicate<ProjectRelBase>() {
- public boolean apply(ProjectRelBase project) {
+ private static final Predicate<Project> PREDICATE2 =
+ new Predicate<Project>() {
+ public boolean apply(Project project) {
return RexOver.containsOver(project.getProjects(), null);
}
};
/**
- * Instance of the rule that applies to a {@link CalcRelBase} that contains
+ * Instance of the rule that applies to a
+ * {@link org.apache.calcite.rel.core.Calc} that contains
* windowed aggregates and converts it into a mixture of
- * {@link org.eigenbase.rel.WindowRel} and {@code CalcRelBase}.
+ * {@link org.apache.calcite.rel.logical.LogicalWindow} and {@code Calc}.
*/
- public static final WindowedAggSplitterRule INSTANCE =
- new WindowedAggSplitterRule(
- operand(CalcRelBase.class, null, PREDICATE, any()),
- "WindowedAggSplitterRule") {
+ public static final ProjectToWindowRule INSTANCE =
+ new ProjectToWindowRule(
+ operand(Calc.class, null, PREDICATE, any()),
+ "ProjectToWindowRule") {
public void onMatch(RelOptRuleCall call) {
- CalcRelBase calc = call.rel(0);
+ Calc calc = call.rel(0);
assert RexOver.containsOver(calc.getProgram());
CalcRelSplitter transform = new WindowedAggRelSplitter(calc);
RelNode newRel = transform.execute();
@@ -74,18 +102,18 @@ public abstract class WindowedAggSplitterRule extends RelOptRule {
/**
* Instance of the rule that can be applied to a
- * {@link org.eigenbase.rel.ProjectRelBase} and that produces, in turn,
- * a mixture of {@code ProjectRel} and {@link org.eigenbase.rel.WindowRel}.
+ * {@link org.apache.calcite.rel.core.Project} and that produces, in turn,
+ * a mixture of {@code LogicalProject}
+ * and {@link org.apache.calcite.rel.logical.LogicalWindow}.
*/
- public static final WindowedAggSplitterRule PROJECT =
- new WindowedAggSplitterRule(
- operand(ProjectRelBase.class, null, PREDICATE2, any()),
- "WindowedAggSplitterRule:project") {
- @Override
- public void onMatch(RelOptRuleCall call) {
- ProjectRelBase project = call.rel(0);
+ public static final ProjectToWindowRule PROJECT =
+ new ProjectToWindowRule(
+ operand(Project.class, null, PREDICATE2, any()),
+ "ProjectToWindowRule:project") {
+ @Override public void onMatch(RelOptRuleCall call) {
+ Project project = call.rel(0);
assert RexOver.containsOver(project.getProjects(), null);
- final RelNode child = project.getChild();
+ final RelNode child = project.getInput();
final RelDataType rowType = project.getRowType();
final RexProgram program =
RexProgram.create(
@@ -94,9 +122,9 @@ public abstract class WindowedAggSplitterRule extends RelOptRule {
null,
project.getRowType(),
project.getCluster().getRexBuilder());
- // temporary CalcRel, never registered
- final CalcRel calc =
- new CalcRel(
+ // temporary LogicalCalc, never registered
+ final LogicalCalc calc =
+ new LogicalCalc(
project.getCluster(),
project.getTraitSet(),
child,
@@ -104,14 +132,13 @@ public abstract class WindowedAggSplitterRule extends RelOptRule {
program,
ImmutableList.<RelCollation>of());
CalcRelSplitter transform = new WindowedAggRelSplitter(calc) {
- @Override
- protected RelNode handle(RelNode rel) {
- if (rel instanceof CalcRel) {
- CalcRel calc = (CalcRel) rel;
+ @Override protected RelNode handle(RelNode rel) {
+ if (rel instanceof LogicalCalc) {
+ LogicalCalc calc = (LogicalCalc) rel;
final RexProgram program = calc.getProgram();
- rel = calc.getChild();
+ rel = calc.getInput();
if (program.getCondition() != null) {
- rel = new FilterRel(
+ rel = new LogicalFilter(
calc.getCluster(),
rel,
program.expandLocalRef(
@@ -140,11 +167,8 @@ public abstract class WindowedAggSplitterRule extends RelOptRule {
//~ Constructors -----------------------------------------------------------
- /**
- * Creates a rule.
- */
- private WindowedAggSplitterRule(
- RelOptRuleOperand operand, String description) {
+ /** Creates a ProjectToWindowRule. */
+ private ProjectToWindowRule(RelOptRuleOperand operand, String description) {
super(operand, description);
}
@@ -155,7 +179,7 @@ public abstract class WindowedAggSplitterRule extends RelOptRule {
* (calls to {@link RexOver}) and ordinary expressions.
*/
static class WindowedAggRelSplitter extends CalcRelSplitter {
- WindowedAggRelSplitter(CalcRelBase calc) {
+ WindowedAggRelSplitter(Calc calc) {
super(
calc,
new RelType[]{
@@ -223,15 +247,14 @@ public abstract class WindowedAggSplitterRule extends RelOptRule {
Util.permAssert(
program.getCondition() == null,
"WindowedAggregateRel cannot accept a condition");
- return WindowRel.create(
+ return LogicalWindow.create(
cluster, traits, child, program, rowType);
}
}
});
}
- @Override
- protected List<Set<Integer>> getCohorts() {
+ @Override protected List<Set<Integer>> getCohorts() {
// Here used to be the implementation that treats all the RexOvers
// as a single Cohort. This is flawed if the RexOvers
// depend on each other (i.e. the second one uses the result
@@ -241,4 +264,4 @@ public abstract class WindowedAggSplitterRule extends RelOptRule {
}
}
-// End WindowedAggSplitterRule.java
+// End ProjectToWindowRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java b/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java
index 4709439..d317237 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java
@@ -14,24 +14,33 @@
* 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.sql.*;
-import org.eigenbase.util.Pair;
-
-import net.hydromatic.linq4j.Ord;
-
-import net.hydromatic.optiq.util.BitSets;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.linq4j.Ord;
+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.SetOp;
+import org.apache.calcite.rel.logical.LogicalProject;
+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.rex.RexUtil;
+import org.apache.calcite.rex.RexVisitorImpl;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.util.BitSets;
+import org.apache.calcite.util.Pair;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Set;
+
/**
* PushProjector is a utility class used to perform operations used in push
* projection rules.
@@ -49,7 +58,7 @@ import com.google.common.collect.Lists;
public class PushProjector {
//~ Instance fields --------------------------------------------------------
- private final ProjectRel origProj;
+ private final LogicalProject origProj;
private final RexNode origFilter;
private final RelNode childRel;
private final ExprCondition preserveExprCondition;
@@ -177,7 +186,7 @@ public class PushProjector {
* be preserved in the projection
*/
public PushProjector(
- ProjectRel origProj,
+ LogicalProject origProj,
RexNode origFilter,
RelNode childRel,
ExprCondition preserveExprCondition) {
@@ -196,8 +205,8 @@ public class PushProjector {
nChildFields = childFields.size();
projRefs = new BitSet(nChildFields);
- if (childRel instanceof JoinRelBase) {
- JoinRelBase joinRel = (JoinRelBase) childRel;
+ if (childRel instanceof Join) {
+ Join joinRel = (Join) childRel;
List<RelDataTypeField> leftFields =
joinRel.getLeft().getRowType().getFieldList();
List<RelDataTypeField> rightFields =
@@ -358,8 +367,8 @@ public class PushProjector {
assert nSystemProject + nProject + nRightProject
== projRefs.cardinality();
- if ((childRel instanceof JoinRelBase)
- || (childRel instanceof SetOpRel)) {
+ if ((childRel instanceof Join)
+ || (childRel instanceof SetOp)) {
// if nothing is projected from the children, arbitrarily project
// the first columns; this is necessary since Fennel doesn't
// handle 0-column projections
@@ -367,7 +376,7 @@ public class PushProjector {
projRefs.set(0);
nProject = 1;
}
- if (childRel instanceof JoinRelBase) {
+ if (childRel instanceof Join) {
if ((nRightProject == 0) && (rightPreserveExprs.size() == 0)) {
projRefs.set(nFields);
nRightProject = 1;
@@ -400,7 +409,7 @@ public class PushProjector {
* of a join
* @return created projection
*/
- public ProjectRel createProjectRefsAndExprs(
+ public LogicalProject createProjectRefsAndExprs(
RelNode projChild,
boolean adjust,
boolean rightSide) {
@@ -463,7 +472,7 @@ public class PushProjector {
((RexCall) projExpr).getOperator().getName()));
}
- return (ProjectRel) RelOptUtil.createProject(
+ return (LogicalProject) RelOptUtil.createProject(
projChild,
Pair.left(newProjects),
Pair.right(newProjects));
@@ -737,7 +746,7 @@ public class PushProjector {
/**
* A functor that replies true or false for a given expression.
*
- * @see org.eigenbase.rel.rules.PushProjector.OperatorExprCondition
+ * @see org.apache.calcite.rel.rules.PushProjector.OperatorExprCondition
*/
public interface ExprCondition {
/**
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
index d89561d..9d9cc2d 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
@@ -14,38 +14,55 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
-
-import java.math.*;
-
-import java.util.*;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.fun.*;
-import org.eigenbase.sql.type.*;
-import org.eigenbase.util.*;
-
-import net.hydromatic.linq4j.Ord;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.linq4j.Ord;
+import org.apache.calcite.plan.Convention;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.logical.LogicalCalc;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.type.SqlTypeUtil;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
import com.google.common.collect.ImmutableList;
-import static org.eigenbase.util.Static.RESOURCE;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.calcite.util.Static.RESOURCE;
/**
* ReduceDecimalsRule is a rule which reduces decimal operations (such as casts
* or arithmetic) into operations involving more primitive types (such as longs
- * and doubles). The rule allows eigenbase implementations to deal with decimals
+ * and doubles). The rule allows Calcite implementations to deal with decimals
* in a consistent manner, while saving the effort of implementing them.
*
- * <p>The rule can be applied to a {@link CalcRel} with a program for which
+ * <p>The rule can be applied to a
+ * {@link org.apache.calcite.rel.logical.LogicalCalc} with a program for which
* {@link RexUtil#requiresDecimalExpansion} returns true. The rule relies on a
* {@link RexShuttle} to walk over relational expressions and replace them.
*
- * <p>While decimals are generally not implemented by the eigenbase runtime, the
+ * <p>While decimals are generally not implemented by the Calcite runtime, the
* rule is optionally applied, in order to support the situation in which we
* would like to push down decimal operations to an external database.
*/
@@ -58,7 +75,7 @@ public class ReduceDecimalsRule extends RelOptRule {
* Creates a ReduceDecimalsRule.
*/
private ReduceDecimalsRule() {
- super(operand(CalcRel.class, any()));
+ super(operand(LogicalCalc.class, any()));
}
//~ Methods ----------------------------------------------------------------
@@ -70,21 +87,21 @@ public class ReduceDecimalsRule extends RelOptRule {
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- CalcRel calcRel = call.rel(0);
+ LogicalCalc calc = call.rel(0);
// Expand decimals in every expression in this program. If no
// expression changes, don't apply the rule.
- final RexProgram program = calcRel.getProgram();
+ final RexProgram program = calc.getProgram();
if (!RexUtil.requiresDecimalExpansion(program, true)) {
return;
}
- final RexBuilder rexBuilder = calcRel.getCluster().getRexBuilder();
+ final RexBuilder rexBuilder = calc.getCluster().getRexBuilder();
final RexShuttle shuttle = new DecimalShuttle(rexBuilder);
RexProgramBuilder programBuilder =
RexProgramBuilder.create(
rexBuilder,
- calcRel.getChild().getRowType(),
+ calc.getInput().getRowType(),
program.getExprList(),
program.getProjectList(),
program.getCondition(),
@@ -93,15 +110,15 @@ public class ReduceDecimalsRule extends RelOptRule {
true);
final RexProgram newProgram = programBuilder.getProgram();
- CalcRel newCalcRel =
- new CalcRel(
- calcRel.getCluster(),
- calcRel.getTraitSet(),
- calcRel.getChild(),
+ LogicalCalc newCalc =
+ new LogicalCalc(
+ calc.getCluster(),
+ calc.getTraitSet(),
+ calc.getInput(),
newProgram.getOutputRowType(),
newProgram,
Collections.<RelCollation>emptyList());
- call.transformTo(newCalcRel);
+ call.transformTo(newCalc);
}
//~ Inner Classes ----------------------------------------------------------
@@ -267,10 +284,10 @@ public class ReduceDecimalsRule extends RelOptRule {
* Rewrites a decimal expression for a specific set of SqlOperator's. In
* general, most expressions are rewritten in such a way that SqlOperator's
* do not have to deal with decimals. Decimals are represented by their
- * unscaled integer representations, similar to {@link
- * BigDecimal#unscaledValue()} (i.e. 10^scale). Once decimals are decoded,
- * SqlOperators can then operate on the integer representations. The value
- * can later be recoded as a decimal.
+ * unscaled integer representations, similar to
+ * {@link BigDecimal#unscaledValue()} (i.e. 10^scale). Once decimals are
+ * decoded, SqlOperators can then operate on the integer representations. The
+ * value can later be recoded as a decimal.
*
* <p>For example, suppose one casts 2.0 as a decima(10,4). The value is
* decoded (20), multiplied by a scale factor (1000), for a result of
@@ -307,12 +324,11 @@ public class ReduceDecimalsRule extends RelOptRule {
}
/**
- * This defaults to the utility method, {@link
- * RexUtil#requiresDecimalExpansion(RexNode, boolean)} which checks
- * general guidelines on whether a rewrite should be considered at all.
- * In general, it is helpful to update the utility method since that
- * method is often used to filter the somewhat expensive rewrite
- * process.
+ * This defaults to the utility method,
+ * {@link RexUtil#requiresDecimalExpansion(RexNode, boolean)} which checks
+ * general guidelines on whether a rewrite should be considered at all. In
+ * general, it is helpful to update the utility method since that method is
+ * often used to filter the somewhat expensive rewrite process.
*
* <p>However, this method provides another place for implementations of
* RexExpander to make a more detailed analysis before deciding on
@@ -420,9 +436,9 @@ public class ReduceDecimalsRule extends RelOptRule {
/**
* Scales down a decimal value, and returns the scaled value as an exact
- * numeric. with the rounding convention {@link BigDecimal#ROUND_HALF_UP
- * BigDecimal.ROUND_HALF_UP}. (Values midway between two points are
- * rounded away from zero.)
+ * numeric. with the rounding convention
+ * {@link BigDecimal#ROUND_HALF_UP BigDecimal.ROUND_HALF_UP}. (Values midway
+ * between two points are rounded away from zero.)
*
* @param value the integer representation of a decimal
* @param scale a value from zero to max precision
@@ -522,8 +538,7 @@ public class ReduceDecimalsRule extends RelOptRule {
// TODO: make a validator exception for this
if (scaleDiff >= maxPrecision) {
- throw Util.needToImplement(
- "Source type with scale " + scale
+ throw Util.needToImplement("Source type with scale " + scale
+ " cannot be converted to target type with scale "
+ required + " because the smallest value of the "
+ "source type is too large to be encoded by the "
@@ -762,7 +777,7 @@ public class ReduceDecimalsRule extends RelOptRule {
|| !SqlTypeUtil.isExactNumeric(toType)) {
throw Util.needToImplement(
"Cast from '" + fromType.toString()
- + "' to '" + toType.toString() + "'");
+ + "' to '" + toType.toString() + "'");
}
int fromScale = fromType.getScale();
int toScale = toType.getScale();
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
index 7025a47..5fb7035 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
@@ -14,19 +14,46 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.rel.rules;
-
-import java.util.*;
-import java.util.regex.*;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.fun.*;
-import org.eigenbase.util.Stacks;
-import org.eigenbase.util.Util;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptPlanner;
+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.Empty;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.logical.LogicalCalc;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.rex.RexDynamicParam;
+import org.apache.calcite.rex.RexFieldAccess;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexLocalRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexOver;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.rex.RexRangeRef;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.rex.RexVisitorImpl;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.fun.SqlRowOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.util.Stacks;
+import org.apache.calcite.util.Util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
/**
* Collection of planner rules that apply various simplifying transformations on
@@ -44,22 +71,23 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
/**
* Regular expression that matches the description of all instances of this
- * rule and {@link ReduceValuesRule} also. Use
+ * rule and {@link ValuesReduceRule} also. Use
* it to prevent the planner from invoking these rules.
*/
public static final Pattern EXCLUSION_PATTERN =
Pattern.compile("Reduce(Expressions|Values)Rule.*");
/**
- * Singleton rule that reduces constants inside a {@link FilterRel}. If the
- * condition is a constant, the filter is removed (if TRUE) or replaced with
- * {@link EmptyRel} (if FALSE or NULL).
+ * Singleton rule that reduces constants inside a
+ * {@link org.apache.calcite.rel.logical.LogicalFilter}. If the condition is a
+ * constant, the filter is removed (if TRUE) or replaced with
+ * {@link org.apache.calcite.rel.core.Empty} (if FALSE or NULL).
*/
public static final ReduceExpressionsRule FILTER_INSTANCE =
- new ReduceExpressionsRule(FilterRel.class,
+ new ReduceExpressionsRule(LogicalFilter.class,
"ReduceExpressionsRule[Filter]") {
public void onMatch(RelOptRuleCall call) {
- FilterRel filter = call.rel(0);
+ LogicalFilter filter = call.rel(0);
List<RexNode> expList = new ArrayList<RexNode>(filter.getChildExps());
RexNode newConditionExp;
boolean reduced;
@@ -77,18 +105,18 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
}
if (newConditionExp.isAlwaysTrue()) {
call.transformTo(
- filter.getChild());
+ filter.getInput());
} else if (
(newConditionExp instanceof RexLiteral)
|| RexUtil.isNullLiteral(newConditionExp, true)) {
call.transformTo(
- new EmptyRel(
+ new Empty(
filter.getCluster(),
filter.getRowType()));
} else if (reduced) {
call.transformTo(
RelOptUtil.createFilter(
- filter.getChild(),
+ filter.getInput(),
expList.get(0)));
} else {
if (newConditionExp instanceof RexCall) {
@@ -110,12 +138,12 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
private void reduceNotNullableFilter(
RelOptRuleCall call,
- FilterRel filter,
+ LogicalFilter filter,
RexCall rexCall,
boolean reverse) {
// If the expression is a IS [NOT] NULL on a non-nullable
// column, then we can either remove the filter or replace
- // it with an EmptyRel.
+ // it with an Empty.
SqlOperator op = rexCall.getOperator();
boolean alwaysTrue;
switch (rexCall.getKind()) {
@@ -137,10 +165,10 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
RexInputRef inputRef = (RexInputRef) operand;
if (!inputRef.getType().isNullable()) {
if (alwaysTrue) {
- call.transformTo(filter.getChild());
+ call.transformTo(filter.getInput());
} else {
call.transformTo(
- new EmptyRel(
+ new Empty(
filter.getCluster(),
filter.getRowType()));
}
@@ -150,21 +178,21 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
};
public static final ReduceExpressionsRule PROJECT_INSTANCE =
- new ReduceExpressionsRule(ProjectRel.class,
+ new ReduceExpressionsRule(LogicalProject.class,
"ReduceExpressionsRule[Project]") {
public void onMatch(RelOptRuleCall call) {
- ProjectRel project = call.rel(0);
+ LogicalProject project = call.rel(0);
List<RexNode> expList =
new ArrayList<RexNode>(project.getChildExps());
if (reduceExpressions(project, expList)) {
call.transformTo(
- new ProjectRel(
+ new LogicalProject(
project.getCluster(),
project.getTraitSet(),
- project.getChild(),
+ project.getInput(),
expList,
project.getRowType(),
- ProjectRel.Flags.BOXED));
+ LogicalProject.Flags.BOXED));
// New plan is absolutely better than old plan.
call.getPlanner().setImportance(project, 0.0);
@@ -173,10 +201,10 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
};
public static final ReduceExpressionsRule JOIN_INSTANCE =
- new ReduceExpressionsRule(JoinRelBase.class,
+ new ReduceExpressionsRule(Join.class,
"ReduceExpressionsRule[Join]") {
public void onMatch(RelOptRuleCall call) {
- final JoinRelBase join = call.rel(0);
+ final Join join = call.rel(0);
List<RexNode> expList = new ArrayList<RexNode>(join.getChildExps());
if (reduceExpressions(join, expList)) {
call.transformTo(
@@ -195,9 +223,10 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
};
public static final ReduceExpressionsRule CALC_INSTANCE =
- new ReduceExpressionsRule(CalcRel.class, "ReduceExpressionsRule[Calc]") {
+ new ReduceExpressionsRule(LogicalCalc.class,
+ "ReduceExpressionsRule[Calc]") {
public void onMatch(RelOptRuleCall call) {
- CalcRel calc = call.rel(0);
+ LogicalCalc calc = call.rel(0);
RexProgram program = calc.getProgram();
final List<RexNode> exprList = program.getExprList();
@@ -216,7 +245,7 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
if (reduceExpressions(calc, expandedExprList)) {
final RexProgramBuilder builder =
new RexProgramBuilder(
- calc.getChild().getRowType(),
+ calc.getInput().getRowType(),
calc.getCluster().getRexBuilder());
List<RexLocalRef> list = new ArrayList<RexLocalRef>();
for (RexNode expr : expandedExprList) {
@@ -234,7 +263,7 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
// condition is always NULL or FALSE - replace calc
// with empty
call.transformTo(
- new EmptyRel(
+ new Empty(
calc.getCluster(),
calc.getRowType()));
return;
@@ -250,10 +279,10 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
program.getOutputRowType().getFieldNames().get(k++));
}
call.transformTo(
- new CalcRel(
+ new LogicalCalc(
calc.getCluster(),
calc.getTraitSet(),
- calc.getChild(),
+ calc.getInput(),
calc.getRowType(),
builder.getProgram(),
calc.getCollationList()));
@@ -328,14 +357,14 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
List<RexNode> reducedValues = new ArrayList<RexNode>();
executor.reduce(rexBuilder, constExps, reducedValues);
- // For ProjectRel, we have to be sure to preserve the result
+ // For Project, we have to be sure to preserve the result
// types, so always cast regardless of the expression type.
- // For other RelNodes like FilterRel, in general, this isn't necessary,
+ // For other RelNodes like Filter, in general, this isn't necessary,
// and the presence of casts could hinder other rules such as sarg
// analysis, which require bare literals. But there are special cases,
// like when the expression is a UDR argument, that need to be
// handled as special cases.
- if (rel instanceof ProjectRel) {
+ if (rel instanceof LogicalProject) {
for (int i = 0; i < reducedValues.size(); i++) {
addCasts.set(i, true);
}
@@ -403,8 +432,7 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
this.addCasts = addCasts;
}
- @Override
- public RexNode visitCall(final RexCall call) {
+ @Override public RexNode visitCall(final RexCall call) {
int i = reducibleExps.indexOf(call);
if (i == -1) {
return super.visitCall(call);
@@ -418,7 +446,7 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
//
// Also, we cannot reduce CAST('abc' AS VARCHAR(4)) to 'abc'.
// If we make 'abc' of type VARCHAR(4), we may later encounter
- // the same expression in a ProjectRel's digest where it has
+ // the same expression in a Project's digest where it has
// type VARCHAR(3), and that's wrong.
replacement =
rexBuilder.makeCast(
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinFilterTransposeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinFilterTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinFilterTransposeRule.java
index 4e961db..9fa288d 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinFilterTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinFilterTransposeRule.java
@@ -14,49 +14,55 @@
* 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.rel.RelFactories.FilterFactory;
-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.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.SemiJoin;
+import org.apache.calcite.rel.logical.LogicalFilter;
/**
- * PushSemiJoinPastFilterRule implements the rule for pushing semijoins down in
- * a tree past a filter in order to trigger other rules that will convert
- * semijoins. SemiJoinRel(FilterRel(X), Y) → FilterRel(SemiJoinRel(X, Y))
+ * Planner rule that pushes
+ * {@link org.apache.calcite.rel.core.SemiJoin}s down in a tree past
+ * a {@link org.apache.calcite.rel.core.Filter}.
+ *
+ * <p>The intention is to trigger other rules that will convert
+ * {@code SemiJoin}s.
+ *
+ * <p>SemiJoin(LogicalFilter(X), Y) → LogicalFilter(SemiJoin(X, Y))
+ *
+ * @see SemiJoinProjectTransposeRule
*/
-public class PushSemiJoinPastFilterRule extends RelOptRule {
- public static final PushSemiJoinPastFilterRule INSTANCE =
- new PushSemiJoinPastFilterRule(RelFactories.DEFAULT_FILTER_FACTORY);
-
- private final FilterFactory filterFactory;
+public class SemiJoinFilterTransposeRule extends RelOptRule {
+ public static final SemiJoinFilterTransposeRule INSTANCE =
+ new SemiJoinFilterTransposeRule();
//~ Constructors -----------------------------------------------------------
/**
- * Creates a PushSemiJoinPastFilterRule.
- * @param filterFactory Factory to create Filter
+ * Creates a SemiJoinFilterTransposeRule.
*/
- public PushSemiJoinPastFilterRule(FilterFactory filterFactory) {
+ private SemiJoinFilterTransposeRule() {
super(
- operand(
- SemiJoinRel.class,
- some(operand(FilterRelBase.class, any()))));
- this.filterFactory = filterFactory;
+ operand(SemiJoin.class,
+ some(operand(LogicalFilter.class, any()))));
}
//~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- SemiJoinRel semiJoin = call.rel(0);
- FilterRelBase filter = call.rel(1);
+ SemiJoin semiJoin = call.rel(0);
+ LogicalFilter filter = call.rel(1);
RelNode newSemiJoin =
- new SemiJoinRel(
+ new SemiJoin(
semiJoin.getCluster(),
semiJoin.getCluster().traitSetOf(Convention.NONE),
- filter.getChild(),
+ filter.getInput(),
semiJoin.getRight(),
semiJoin.getCondition(),
semiJoin.getLeftKeys(),
@@ -65,10 +71,10 @@ public class PushSemiJoinPastFilterRule extends RelOptRule {
RelNode newFilter =
RelOptUtil.createFilter(
newSemiJoin,
- filter.getCondition(), filterFactory);
+ filter.getCondition());
call.transformTo(newFilter);
}
}
-// End PushSemiJoinPastFilterRule.java
+// End SemiJoinFilterTransposeRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
index 21cde7f..a859161 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
@@ -14,53 +14,58 @@
* 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;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.Convention;
+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.SemiJoin;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.util.ImmutableIntList;
+
+import java.util.ArrayList;
+import java.util.List;
/**
- * PushSemiJoinPastJoinRule implements the rule for pushing semi-joins down in a
- * tree past a join in order to trigger other rules that will convert
- * semi-joins.
+ * Planner rule that pushes a {@link org.apache.calcite.rel.core.SemiJoin}
+ * down in a tree past a {@link org.apache.calcite.rel.core.Join}
+ * in order to trigger other rules that will convert {@code SemiJoin}s.
*
* <ul>
- * <li>SemiJoinRel(JoinRel(X, Y), Z) → JoinRel(SemiJoinRel(X, Z), Y)
- * <li>SemiJoinRel(JoinRel(X, Y), Z) → JoinRel(X, SemiJoinRel(Y, Z))
+ * <li>SemiJoin(LogicalJoin(X, Y), Z) → LogicalJoin(SemiJoin(X, Z), Y)
+ * <li>SemiJoin(LogicalJoin(X, Y), Z) → LogicalJoin(X, SemiJoin(Y, Z))
* </ul>
*
* <p>Whether this
* first or second conversion is applied depends on which operands actually
* participate in the semi-join.</p>
*/
-public class PushSemiJoinPastJoinRule extends RelOptRule {
- public static final PushSemiJoinPastJoinRule INSTANCE =
- new PushSemiJoinPastJoinRule();
+public class SemiJoinJoinTransposeRule extends RelOptRule {
+ public static final SemiJoinJoinTransposeRule INSTANCE =
+ new SemiJoinJoinTransposeRule();
//~ Constructors -----------------------------------------------------------
/**
- * Creates a PushSemiJoinPastJoinRule.
+ * Creates a SemiJoinJoinTransposeRule.
*/
- private PushSemiJoinPastJoinRule() {
+ private SemiJoinJoinTransposeRule() {
super(
- operand(
- SemiJoinRel.class,
- some(operand(JoinRelBase.class, any()))));
+ operand(SemiJoin.class,
+ some(operand(Join.class, any()))));
}
//~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- SemiJoinRel semiJoin = call.rel(0);
- final JoinRelBase join = call.rel(1);
- if (join instanceof SemiJoinRel) {
+ SemiJoin semiJoin = call.rel(0);
+ final Join join = call.rel(1);
+ if (join instanceof SemiJoin) {
return;
}
final ImmutableIntList leftKeys = semiJoin.getLeftKeys();
@@ -150,8 +155,8 @@ public class PushSemiJoinPastJoinRule extends RelOptRule {
} else {
leftSemiJoinOp = join.getRight();
}
- SemiJoinRel newSemiJoin =
- new SemiJoinRel(
+ SemiJoin newSemiJoin =
+ new SemiJoin(
semiJoin.getCluster(),
semiJoin.getCluster().traitSetOf(Convention.NONE),
leftSemiJoinOp,
@@ -216,4 +221,4 @@ public class PushSemiJoinPastJoinRule extends RelOptRule {
}
}
-// End PushSemiJoinPastJoinRule.java
+// End SemiJoinJoinTransposeRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinProjectTransposeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinProjectTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinProjectTransposeRule.java
index 9d7d4b0..dfae5f0 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinProjectTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinProjectTransposeRule.java
@@ -14,52 +14,63 @@
* 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.ImmutableIntList;
-import org.eigenbase.util.Pair;
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.Convention;
+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.SemiJoin;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+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.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.calcite.util.Pair;
+
+import java.util.ArrayList;
+import java.util.List;
/**
- * PushSemiJoinPastProjectRule implements the rule for pushing semijoins down in
- * a tree past a project in order to trigger other rules that will convert
- * semijoins.
+ * Planner rule that pushes
+ * a {@link org.apache.calcite.rel.core.SemiJoin} down in a tree past
+ * a {@link org.apache.calcite.rel.core.Project}.
+ *
+ * <p>The intention is to trigger other rules that will convert
+ * {@code SemiJoin}s.
*
- * <p>SemiJoinRel(ProjectRel(X), Y) → ProjectRel(SemiJoinRel(X, Y))
+ * <p>SemiJoin(LogicalProject(X), Y) → LogicalProject(SemiJoin(X, Y))
+ *
+ * @see org.apache.calcite.rel.rules.SemiJoinFilterTransposeRule
*/
-public class PushSemiJoinPastProjectRule extends RelOptRule {
- public static final PushSemiJoinPastProjectRule INSTANCE =
- new PushSemiJoinPastProjectRule(RelFactories.DEFAULT_PROJECT_FACTORY);
-
- private final RelFactories.ProjectFactory projectFactory;
+public class SemiJoinProjectTransposeRule extends RelOptRule {
+ public static final SemiJoinProjectTransposeRule INSTANCE =
+ new SemiJoinProjectTransposeRule();
//~ Constructors -----------------------------------------------------------
/**
- * Creates a PushSemiJoinPastProjectRule.
- *
- * @param projectFactory factory to create Project
+ * Creates a SemiJoinProjectTransposeRule.
*/
- public PushSemiJoinPastProjectRule(ProjectFactory projectFactory) {
+ private SemiJoinProjectTransposeRule() {
super(
- operand(
- SemiJoinRel.class,
- some(operand(ProjectRel.class, any()))));
- this.projectFactory = projectFactory;
+ operand(SemiJoin.class,
+ some(operand(LogicalProject.class, any()))));
}
//~ Methods ----------------------------------------------------------------
- // implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- SemiJoinRel semiJoin = call.rel(0);
- ProjectRel project = call.rel(1);
+ SemiJoin semiJoin = call.rel(0);
+ LogicalProject project = call.rel(1);
// convert the LHS semijoin keys to reference the child projection
// expression; all projection expressions must be RexInputRefs,
@@ -76,11 +87,11 @@ public class PushSemiJoinPastProjectRule extends RelOptRule {
// pulled up
RexNode newCondition = adjustCondition(project, semiJoin);
- SemiJoinRel newSemiJoin =
- new SemiJoinRel(
+ SemiJoin newSemiJoin =
+ new SemiJoin(
semiJoin.getCluster(),
semiJoin.getCluster().traitSetOf(Convention.NONE),
- project.getChild(),
+ project.getInput(),
semiJoin.getRight(),
newCondition,
ImmutableIntList.copyOf(newLeftKeys),
@@ -90,7 +101,7 @@ public class PushSemiJoinPastProjectRule extends RelOptRule {
// are the same as the original because they only reference the LHS
// of the semijoin and the semijoin only projects out the LHS
RelNode newProject =
- projectFactory.createProject(
+ RelOptUtil.createProject(
newSemiJoin,
projExprs,
project.getRowType().getFieldNames());
@@ -104,11 +115,11 @@ public class PushSemiJoinPastProjectRule extends RelOptRule {
* that references to the LHS of a semijoin should now reference the
* children of the project that's on the LHS.
*
- * @param project ProjectRel on the LHS of the semijoin
+ * @param project LogicalProject on the LHS of the semijoin
* @param semiJoin the semijoin
* @return the modified semijoin condition
*/
- private RexNode adjustCondition(ProjectRel project, SemiJoinRel semiJoin) {
+ private RexNode adjustCondition(LogicalProject project, SemiJoin semiJoin) {
// create two RexPrograms -- the bottom one representing a
// concatenation of the project and the RHS of the semijoin and the
// top one representing the semijoin condition
@@ -120,8 +131,8 @@ public class PushSemiJoinPastProjectRule extends RelOptRule {
// for the bottom RexProgram, the input is a concatenation of the
// child of the project and the RHS of the semijoin
RelDataType bottomInputRowType =
- JoinRelBase.deriveJoinRowType(
- project.getChild().getRowType(),
+ Join.deriveJoinRowType(
+ project.getInput().getRowType(),
rightChild.getRowType(),
JoinRelType.INNER,
typeFactory,
@@ -135,7 +146,7 @@ public class PushSemiJoinPastProjectRule extends RelOptRule {
for (Pair<RexNode, String> pair : project.getNamedProjects()) {
bottomProgramBuilder.addProject(pair.left, pair.right);
}
- int nLeftFields = project.getChild().getRowType().getFieldCount();
+ int nLeftFields = project.getInput().getRowType().getFieldCount();
List<RelDataTypeField> rightFields =
rightChild.getRowType().getFieldList();
int nRightFields = rightFields.size();
@@ -151,7 +162,7 @@ public class PushSemiJoinPastProjectRule extends RelOptRule {
// input rowtype into the top program is the concatenation of the
// project and the RHS of the semijoin
RelDataType topInputRowType =
- JoinRelBase.deriveJoinRowType(
+ Join.deriveJoinRowType(
project.getRowType(),
rightChild.getRowType(),
JoinRelType.INNER,
@@ -180,4 +191,4 @@ public class PushSemiJoinPastProjectRule extends RelOptRule {
}
}
-// End PushSemiJoinPastProjectRule.java
+// End SemiJoinProjectTransposeRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRemoveRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRemoveRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRemoveRule.java
index 40f2bd7..4c6a20d 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRemoveRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRemoveRule.java
@@ -14,36 +14,39 @@
* 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.relopt.*;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.core.SemiJoin;
/**
- * RemoveSemiJoinRule implements the rule that removes semijoins from a join
- * tree if it turns out it's not possible to convert a SemiJoinRel to an indexed
- * scan on a join factor. Namely, if the join factor does not reduce to a single
- * table that can be scanned using an index. This rule should only be applied
- * after attempts have been made to convert SemiJoinRels.
+ * Planner rule that removes a {@link org.apache.calcite.rel.core.SemiJoin}s
+ * from a join tree.
+ *
+ * <p>It is invoked after attempts have been made to convert a SemiJoin to an
+ * indexed scan on a join factor have failed. Namely, if the join factor does
+ * not reduce to a single table that can be scanned using an index.
+ *
+ * <p>It should only be enabled if all SemiJoins in the plan are advisory; that
+ * is, they can be safely dropped without affecting the semantics of the query.
*/
-public class RemoveSemiJoinRule extends RelOptRule {
- public static final RemoveSemiJoinRule INSTANCE =
- new RemoveSemiJoinRule();
+public class SemiJoinRemoveRule extends RelOptRule {
+ public static final SemiJoinRemoveRule INSTANCE =
+ new SemiJoinRemoveRule();
//~ Constructors -----------------------------------------------------------
- /**
- * Creates a RemoveSemiJoinRule.
- */
- private RemoveSemiJoinRule() {
- super(operand(SemiJoinRel.class, any()));
+ /** Creates a SemiJoinRemoveRule. */
+ private SemiJoinRemoveRule() {
+ super(operand(SemiJoin.class, any()));
}
//~ Methods ----------------------------------------------------------------
- // implement RelOptRule
public void onMatch(RelOptRuleCall call) {
call.transformTo(call.rel(0).getInput(0));
}
}
-// End RemoveSemiJoinRule.java
+// End SemiJoinRemoveRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
index cd06dd8..bedea88 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
@@ -14,49 +14,48 @@
* 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.BitSet;
-import java.util.List;
-
-import org.eigenbase.rel.AggregateRelBase;
-import org.eigenbase.rel.JoinInfo;
-import org.eigenbase.rel.JoinRelBase;
-import org.eigenbase.rel.ProjectRelBase;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.Convention;
-import org.eigenbase.relopt.RelOptRule;
-import org.eigenbase.relopt.RelOptRuleCall;
-import org.eigenbase.relopt.RelOptUtil;
-import org.eigenbase.util.ImmutableIntList;
-import org.eigenbase.util.IntList;
-
-import net.hydromatic.optiq.util.BitSets;
+import org.apache.calcite.plan.Convention;
+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.Aggregate;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinInfo;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.core.SemiJoin;
+import org.apache.calcite.util.BitSets;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.calcite.util.IntList;
import com.google.common.collect.Lists;
+import java.util.BitSet;
+import java.util.List;
+
/**
* Planner rule that creates a {@code SemiJoinRule} from a
- * {@link org.eigenbase.rel.JoinRelBase} on top of a
- * {@link org.eigenbase.rel.AggregateRel}.
+ * {@link org.apache.calcite.rel.core.Join} on top of a
+ * {@link org.apache.calcite.rel.logical.LogicalAggregate}.
*/
public class SemiJoinRule extends RelOptRule {
public static final SemiJoinRule INSTANCE = new SemiJoinRule();
private SemiJoinRule() {
super(
- operand(ProjectRelBase.class,
- some(operand(JoinRelBase.class,
+ operand(Project.class,
+ some(operand(Join.class,
some(operand(RelNode.class, any()),
- operand(AggregateRelBase.class, any()))))));
+ operand(Aggregate.class, any()))))));
}
- @Override
- public void onMatch(RelOptRuleCall call) {
- final ProjectRelBase project = call.rel(0);
- final JoinRelBase join = call.rel(1);
+ @Override public void onMatch(RelOptRuleCall call) {
+ final Project project = call.rel(0);
+ final Join join = call.rel(1);
final RelNode left = call.rel(2);
- final AggregateRelBase aggregate = call.rel(3);
+ final Aggregate aggregate = call.rel(3);
final BitSet bits = RelOptUtil.InputFinder.bits(project.getProjects(),
null);
final BitSet rightBits = BitSets.range(left.getRowType().getFieldCount(),
@@ -75,16 +74,16 @@ public class SemiJoinRule extends RelOptRule {
for (int key : joinInfo.rightKeys) {
newRightKeys.add(aggregateKeys.get(key));
}
- final SemiJoinRel semiJoin =
- new SemiJoinRel(join.getCluster(),
+ final SemiJoin semiJoin =
+ new SemiJoin(join.getCluster(),
join.getCluster().traitSetOf(Convention.NONE),
- left, aggregate.getChild(),
+ left, aggregate.getInput(),
join.getCondition(), joinInfo.leftKeys,
ImmutableIntList.copyOf(newRightKeys));
- final ProjectRelBase newProject =
+ final Project newProject =
project.copy(project.getTraitSet(), semiJoin, project.getProjects(),
project.getRowType());
- call.transformTo(RemoveTrivialProjectRule.strip(newProject));
+ call.transformTo(ProjectRemoveRule.strip(newProject));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java
index d665b19..60cfc53 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java
@@ -14,43 +14,54 @@
* 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.Map;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.rex.RexUtil;
-import org.eigenbase.util.mapping.Mappings;
+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.RelCollation;
+import org.apache.calcite.rel.RelFieldCollation;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Sort;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.util.mapping.Mappings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+
/**
- * Planner rule that pushes a {@link SortRel} past a {@link ProjectRel}.
+ * Planner rule that pushes
+ * a {@link org.apache.calcite.rel.core.Sort}
+ * past a {@link org.apache.calcite.rel.logical.LogicalProject}.
+ *
+ * @see org.apache.calcite.rel.rules.ProjectSortTransposeRule
*/
-public class PushSortPastProjectRule extends RelOptRule {
- public static final PushSortPastProjectRule INSTANCE =
- new PushSortPastProjectRule();
+public class SortProjectTransposeRule extends RelOptRule {
+ public static final SortProjectTransposeRule INSTANCE =
+ new SortProjectTransposeRule();
//~ Constructors -----------------------------------------------------------
/**
- * Creates a PushSortPastProjectRule.
+ * Creates a SortProjectTransposeRule.
*/
- private PushSortPastProjectRule() {
+ private SortProjectTransposeRule() {
super(
operand(
- SortRel.class,
- operand(ProjectRel.class, any())));
+ Sort.class,
+ operand(LogicalProject.class, any())));
}
//~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- final SortRel sort = call.rel(0);
- final ProjectRel project = call.rel(1);
+ final Sort sort = call.rel(0);
+ final LogicalProject project = call.rel(1);
final RelOptCluster cluster = project.getCluster();
if (sort.getConvention() != project.getConvention()) {
@@ -61,7 +72,7 @@ public class PushSortPastProjectRule extends RelOptRule {
// relies on non-trivial expressions, we can't push.
final Mappings.TargetMapping map =
RelOptUtil.permutation(
- project.getProjects(), project.getChild().getRowType());
+ project.getProjects(), project.getInput().getRowType());
for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) {
if (map.getTargetOpt(fc.getFieldIndex()) < 0) {
return;
@@ -70,10 +81,10 @@ public class PushSortPastProjectRule extends RelOptRule {
final RelCollation newCollation =
cluster.traitSetOf().canonize(
RexUtil.apply(map, sort.getCollation()));
- final SortRel newSort =
+ final Sort newSort =
sort.copy(
sort.getTraitSet().replace(newCollation),
- project.getChild(),
+ project.getInput(),
newCollation,
sort.offset,
sort.fetch);
@@ -86,10 +97,10 @@ public class PushSortPastProjectRule extends RelOptRule {
// (but only if the sort is not also applying an offset/limit).
Map<RelNode, RelNode> equiv =
sort.offset == null && sort.fetch == null
- ? ImmutableMap.<RelNode, RelNode>of(newSort, project.getChild())
+ ? ImmutableMap.<RelNode, RelNode>of(newSort, project.getInput())
: ImmutableMap.<RelNode, RelNode>of();
call.transformTo(newProject, equiv);
}
}
-// End PushSortPastProjectRule.java
+// End SortProjectTransposeRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java
index 03425e0..bd56821 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java
@@ -14,32 +14,37 @@
* 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.RelTraitSet;
+import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.RelCollationTraitDef;
+import org.apache.calcite.rel.core.Sort;
/**
- * Planner rule that removes a {@link SortRel} if its input is already sorted.
- * Requires {@link RelCollationTraitDef}.
+ * Planner rule that removes
+ * a {@link org.apache.calcite.rel.core.Sort} if its input is already sorted.
+ *
+ * <p>Requires {@link RelCollationTraitDef}.
*/
-public class RemoveSortRule extends RelOptRule {
- public static final RemoveSortRule INSTANCE = new RemoveSortRule();
+public class SortRemoveRule extends RelOptRule {
+ public static final SortRemoveRule INSTANCE = new SortRemoveRule();
- private RemoveSortRule() {
+ private SortRemoveRule() {
super(
- operand(SortRel.class, any()),
- "RemoveSortRule");
+ operand(Sort.class, any()),
+ "SortRemoveRule");
}
- @Override
- public void onMatch(RelOptRuleCall call) {
+ @Override public void onMatch(RelOptRuleCall call) {
if (!call.getPlanner().getRelTraitDefs()
.contains(RelCollationTraitDef.INSTANCE)) {
// Collation is not an active trait.
return;
}
- final SortRel sort = call.rel(0);
+ final Sort sort = call.rel(0);
if (sort.offset != null || sort.fetch != null) {
// Don't remove sort if would also remove OFFSET or LIMIT.
return;
@@ -50,9 +55,9 @@ public class RemoveSortRule extends RelOptRule {
final RelCollation collation = sort.getCollation();
assert collation == sort.getTraitSet()
.getTrait(RelCollationTraitDef.INSTANCE);
- final RelTraitSet traits = sort.getChild().getTraitSet().replace(collation);
- call.transformTo(convert(sort.getChild(), traits));
+ final RelTraitSet traits = sort.getInput().getTraitSet().replace(collation);
+ call.transformTo(convert(sort.getInput(), traits));
}
}
-// End RemoveSortRule.java
+// End SortRemoveRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/TableScanRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/TableScanRule.java b/core/src/main/java/org/apache/calcite/rel/rules/TableScanRule.java
index 4b65808..208fc89 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/TableScanRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/TableScanRule.java
@@ -14,30 +14,35 @@
* 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.RelOptTable;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalTableScan;
/**
- * Planner rule that converts a {@link TableAccessRel} to the result of calling
- * {@link RelOptTable#toRel}.
+ * Planner rule that converts a
+ * {@link org.apache.calcite.rel.logical.LogicalTableScan} to the result
+ * of calling {@link RelOptTable#toRel}.
*/
-public class TableAccessRule extends RelOptRule {
+public class TableScanRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
- public static final TableAccessRule INSTANCE = new TableAccessRule();
+ public static final TableScanRule INSTANCE = new TableScanRule();
//~ Constructors -----------------------------------------------------------
- private TableAccessRule() {
- super(operand(TableAccessRel.class, any()));
+ private TableScanRule() {
+ super(operand(LogicalTableScan.class, any()));
}
//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
- final TableAccessRel oldRel = call.rel(0);
+ final LogicalTableScan oldRel = call.rel(0);
RelNode newRel =
oldRel.getTable().toRel(
RelOptUtil.getContext(oldRel.getCluster()));
@@ -45,4 +50,4 @@ public class TableAccessRule extends RelOptRule {
}
}
-// End TableAccessRule.java
+// End TableScanRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/UnionEliminatorRule.java
----------------------------------------------------------------------
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 7664b5d..f78704b 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
@@ -14,10 +14,11 @@
* 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.rel.logical.LogicalUnion;
/**
* <code>UnionEliminatorRule</code> checks to see if its possible to optimize a
@@ -34,13 +35,13 @@ public class UnionEliminatorRule extends RelOptRule {
* Creates a UnionEliminatorRule.
*/
private UnionEliminatorRule() {
- super(operand(UnionRel.class, any()));
+ super(operand(LogicalUnion.class, any()));
}
//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
- UnionRel union = call.rel(0);
+ LogicalUnion union = call.rel(0);
if (union.getInputs().size() != 1) {
return;
}
@@ -49,7 +50,7 @@ public class UnionEliminatorRule extends RelOptRule {
}
// REVIEW jvs 14-Mar-2006: why don't we need to register
- // the equivalence here like we do in RemoveDistinctRule?
+ // the equivalence here like we do in AggregateRemoveRule?
call.transformTo(union.getInputs().get(0));
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/UnionMergeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/UnionMergeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/UnionMergeRule.java
index a0e3f6f..f772777 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/UnionMergeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/UnionMergeRule.java
@@ -14,32 +14,35 @@
* 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.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalUnion;
+import org.apache.calcite.util.Util;
import java.util.ArrayList;
import java.util.List;
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.util.Util;
-
/**
- * CombineUnionsRule implements the rule for combining two non-distinct
- * {@link UnionRel}s into a single {@link UnionRel}.
+ * UnionMergeRule implements the rule for combining two
+ * non-distinct {@link org.apache.calcite.rel.logical.LogicalUnion}s
+ * into a single {@link org.apache.calcite.rel.logical.LogicalUnion}.
*/
-public class CombineUnionsRule extends RelOptRule {
- public static final CombineUnionsRule INSTANCE =
- new CombineUnionsRule();
+public class UnionMergeRule extends RelOptRule {
+ public static final UnionMergeRule INSTANCE =
+ new UnionMergeRule();
//~ Constructors -----------------------------------------------------------
/**
- * Creates a CombineUnionsRule.
+ * Creates a UnionMergeRule.
*/
- private CombineUnionsRule() {
+ private UnionMergeRule() {
super(
operand(
- UnionRel.class,
+ LogicalUnion.class,
operand(RelNode.class, any()),
operand(RelNode.class, any())));
}
@@ -48,50 +51,50 @@ public class CombineUnionsRule extends RelOptRule {
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
- UnionRel topUnionRel = call.rel(0);
- UnionRel bottomUnionRel;
+ LogicalUnion topUnion = call.rel(0);
+ LogicalUnion bottomUnion;
- // We want to combine the UnionRel that's in the second input first.
+ // We want to combine the Union that's in the second input first.
// Hence, that's why the rule pattern matches on generic RelNodes
// rather than explicit UnionRels. By doing so, and firing this rule
// in a bottom-up order, it allows us to only specify a single
// pattern for this rule.
- if (call.rel(2) instanceof UnionRel) {
- bottomUnionRel = call.rel(2);
- } else if (call.rel(1) instanceof UnionRel) {
- bottomUnionRel = call.rel(1);
+ if (call.rel(2) instanceof LogicalUnion) {
+ bottomUnion = call.rel(2);
+ } else if (call.rel(1) instanceof LogicalUnion) {
+ bottomUnion = call.rel(1);
} else {
return;
}
// If distincts haven't been removed yet, defer invoking this rule
- if (!topUnionRel.all || !bottomUnionRel.all) {
+ if (!topUnion.all || !bottomUnion.all) {
return;
}
// Combine the inputs from the bottom union with the other inputs from
// the top union
List<RelNode> unionInputs = new ArrayList<RelNode>();
- if (call.rel(2) instanceof UnionRel) {
- assert topUnionRel.getInputs().size() == 2;
- unionInputs.add(topUnionRel.getInput(0));
- unionInputs.addAll(bottomUnionRel.getInputs());
+ if (call.rel(2) instanceof LogicalUnion) {
+ assert topUnion.getInputs().size() == 2;
+ unionInputs.add(topUnion.getInput(0));
+ unionInputs.addAll(bottomUnion.getInputs());
} else {
- unionInputs.addAll(bottomUnionRel.getInputs());
- unionInputs.addAll(Util.skip(topUnionRel.getInputs()));
+ unionInputs.addAll(bottomUnion.getInputs());
+ unionInputs.addAll(Util.skip(topUnion.getInputs()));
}
assert unionInputs.size()
- == bottomUnionRel.getInputs().size()
- + topUnionRel.getInputs().size()
+ == bottomUnion.getInputs().size()
+ + topUnion.getInputs().size()
- 1;
- UnionRel newUnionRel =
- new UnionRel(
- topUnionRel.getCluster(),
+ LogicalUnion newUnion =
+ new LogicalUnion(
+ topUnion.getCluster(),
unionInputs,
true);
- call.transformTo(newUnionRel);
+ call.transformTo(newUnion);
}
}
-// End CombineUnionsRule.java
+// End UnionMergeRule.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/UnionToDistinctRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/UnionToDistinctRule.java b/core/src/main/java/org/apache/calcite/rel/rules/UnionToDistinctRule.java
index 9a3227a..39a6d92 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/UnionToDistinctRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/UnionToDistinctRule.java
@@ -14,15 +14,20 @@
* 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.logical.LogicalUnion;
/**
- * <code>UnionToDistinctRule</code> translates a distinct {@link UnionRel}
- * (<code>all</code> = <code>false</code>) into an {@link AggregateRel} on top
- * of a non-distinct {@link UnionRel} (<code>all</code> = <code>true</code>).
+ * Planner rule that translates a distinct
+ * {@link org.apache.calcite.rel.logical.LogicalUnion}
+ * (<code>all</code> = <code>false</code>)
+ * into an {@link org.apache.calcite.rel.logical.LogicalAggregate}
+ * on top of a non-distinct {@link org.apache.calcite.rel.logical.LogicalUnion}
+ * (<code>all</code> = <code>true</code>).
*/
public class UnionToDistinctRule extends RelOptRule {
public static final UnionToDistinctRule INSTANCE =
@@ -34,18 +39,18 @@ public class UnionToDistinctRule extends RelOptRule {
* Creates a UnionToDistinctRule.
*/
private UnionToDistinctRule() {
- super(operand(UnionRel.class, any()));
+ super(operand(LogicalUnion.class, any()));
}
//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
- UnionRel union = call.rel(0);
+ LogicalUnion union = call.rel(0);
if (union.all) {
return; // nothing to do
}
- UnionRel unionAll =
- new UnionRel(
+ LogicalUnion unionAll =
+ new LogicalUnion(
union.getCluster(),
union.getInputs(),
true);
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java
index cded234..d3f8d6f 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java
@@ -14,22 +14,37 @@
* 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.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Empty;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.logical.LogicalValues;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.util.Util;
+import org.apache.calcite.util.trace.CalciteTrace;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.rex.*;
-import org.eigenbase.trace.EigenbaseTrace;
-import org.eigenbase.util.Util;
-
/**
* Planner rule that folds projections and filters into an underlying
- * {@link ValuesRel}. Returns an {@link EmptyRel} if all rows are filtered away.
+ * {@link org.apache.calcite.rel.logical.LogicalValues}.
+ *
+ * <p>Returns a simplified {@code Values},
+ * or an {@link org.apache.calcite.rel.core.Empty} if all rows are
+ * filtered away.
*
* <p>For example,</p>
*
@@ -40,23 +55,23 @@ import org.eigenbase.util.Util;
*
* <blockquote><code>select x from (values (-2), (-4))</code></blockquote>
*/
-public abstract class ReduceValuesRule extends RelOptRule {
+public abstract class ValuesReduceRule extends RelOptRule {
//~ Static fields/initializers ---------------------------------------------
- private static final Logger LOGGER = EigenbaseTrace.getPlannerTracer();
+ private static final Logger LOGGER = CalciteTrace.getPlannerTracer();
/**
* Instance of this rule that applies to the pattern
* Filter(Values).
*/
- public static final ReduceValuesRule FILTER_INSTANCE =
- new ReduceValuesRule(
- operand(FilterRel.class,
- operand(ValuesRel.class, none())),
- "ReduceValuesRule[Filter") {
+ public static final ValuesReduceRule FILTER_INSTANCE =
+ new ValuesReduceRule(
+ operand(LogicalFilter.class,
+ operand(LogicalValues.class, none())),
+ "ValuesReduceRule[Filter") {
public void onMatch(RelOptRuleCall call) {
- FilterRel filter = call.rel(0);
- ValuesRel values = call.rel(1);
+ LogicalFilter filter = call.rel(0);
+ LogicalValues values = call.rel(1);
apply(call, null, filter, values);
}
};
@@ -65,14 +80,14 @@ public abstract class ReduceValuesRule extends RelOptRule {
* Instance of this rule that applies to the pattern
* Project(Values).
*/
- public static final ReduceValuesRule PROJECT_INSTANCE =
- new ReduceValuesRule(
- operand(ProjectRel.class,
- operand(ValuesRel.class, none())),
- "ReduceValuesRule[Project]") {
+ public static final ValuesReduceRule PROJECT_INSTANCE =
+ new ValuesReduceRule(
+ operand(LogicalProject.class,
+ operand(LogicalValues.class, none())),
+ "ValuesReduceRule[Project]") {
public void onMatch(RelOptRuleCall call) {
- ProjectRel project = call.rel(0);
- ValuesRel values = call.rel(1);
+ LogicalProject project = call.rel(0);
+ LogicalValues values = call.rel(1);
apply(call, project, null, values);
}
};
@@ -81,16 +96,16 @@ public abstract class ReduceValuesRule extends RelOptRule {
* Singleton instance of this rule that applies to the pattern
* Project(Filter(Values)).
*/
- public static final ReduceValuesRule PROJECT_FILTER_INSTANCE =
- new ReduceValuesRule(
- operand(ProjectRel.class,
- operand(FilterRel.class,
- operand(ValuesRel.class, none()))),
- "ReduceValuesRule[Project+Filter]") {
+ public static final ValuesReduceRule PROJECT_FILTER_INSTANCE =
+ new ValuesReduceRule(
+ operand(LogicalProject.class,
+ operand(LogicalFilter.class,
+ operand(LogicalValues.class, none()))),
+ "ValuesReduceRule[Project+Filter]") {
public void onMatch(RelOptRuleCall call) {
- ProjectRel project = call.rel(0);
- FilterRel filter = call.rel(1);
- ValuesRel values = call.rel(2);
+ LogicalProject project = call.rel(0);
+ LogicalFilter filter = call.rel(1);
+ LogicalValues values = call.rel(2);
apply(call, project, filter, values);
}
};
@@ -98,11 +113,11 @@ public abstract class ReduceValuesRule extends RelOptRule {
//~ Constructors -----------------------------------------------------------
/**
- * Creates a ReduceValuesRule.
+ * Creates a ValuesReduceRule.
*
* @param operand class of rels to which this rule should apply
*/
- private ReduceValuesRule(RelOptRuleOperand operand, String desc) {
+ private ValuesReduceRule(RelOptRuleOperand operand, String desc) {
super(operand, desc);
Util.discard(LOGGER);
}
@@ -117,8 +132,8 @@ public abstract class ReduceValuesRule extends RelOptRule {
* @param filter Filter, may be null
* @param values Values rel to be reduced
*/
- protected void apply(RelOptRuleCall call, ProjectRel project,
- FilterRel filter, ValuesRel values) {
+ protected void apply(RelOptRuleCall call, LogicalProject project,
+ LogicalFilter filter, LogicalValues values) {
assert values != null;
assert filter != null || project != null;
final RexNode conditionExpr =
@@ -203,12 +218,12 @@ public abstract class ReduceValuesRule extends RelOptRule {
final RelNode newRel;
if (tupleList.isEmpty()) {
newRel =
- new EmptyRel(
+ new Empty(
values.getCluster(),
rowType);
} else {
newRel =
- new ValuesRel(
+ new LogicalValues(
values.getCluster(),
rowType,
tupleList);
@@ -241,4 +256,4 @@ public abstract class ReduceValuesRule extends RelOptRule {
}
}
-// End ReduceValuesRule.java
+// End ValuesReduceRule.java