Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.apache.calcite.plan.volcano;

import org.apache.calcite.plan.RelOptRuleOperand;
import org.apache.calcite.plan.SubstitutionRule;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.rules.SubstitutionRule;
import org.apache.calcite.util.Util;
import org.apache.calcite.util.trace.CalciteTrace;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.calcite.plan.RelTrait;
import org.apache.calcite.plan.RelTraitDef;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.PhysicalNode;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.convert.Converter;
import org.apache.calcite.rel.convert.ConverterRule;
Expand All @@ -46,6 +47,7 @@
import org.apache.calcite.rel.metadata.RelMdUtil;
import org.apache.calcite.rel.metadata.RelMetadataProvider;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rel.rules.TransformationRule;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.runtime.Hook;
import org.apache.calcite.sql.SqlExplainLevel;
Expand Down Expand Up @@ -410,6 +412,10 @@ public boolean addRule(RelOptRule rule) {
for (RelOptRuleOperand operand : rule.getOperands()) {
for (Class<? extends RelNode> subClass
: subClasses(operand.getMatchedClass())) {
if (PhysicalNode.class.isAssignableFrom(subClass)
&& rule instanceof TransformationRule) {
continue;
}
classOperands.put(subClass, operand);
}
}
Expand Down Expand Up @@ -456,10 +462,14 @@ public boolean removeRule(RelOptRule rule) {
@Override protected void onNewClass(RelNode node) {
super.onNewClass(node);

final boolean isPhysical = node instanceof PhysicalNode;
// Create mappings so that instances of this class will match existing
// operands.
final Class<? extends RelNode> clazz = node.getClass();
for (RelOptRule rule : mapDescToRule.values()) {
if (isPhysical && rule instanceof TransformationRule) {
continue;
}
for (RelOptRuleOperand operand : rule.getOperands()) {
if (operand.getMatchedClass().isAssignableFrom(clazz)) {
classOperands.put(clazz, operand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.RelOptRuleOperand;
import org.apache.calcite.plan.RelOptRuleOperandChildPolicy;
import org.apache.calcite.plan.SubstitutionRule;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.rules.SubstitutionRule;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
* <p>The constructor is parameterized to allow any sub-class of
* {@link org.apache.calcite.rel.core.Join}.</p>
*/
public abstract class AbstractJoinExtractFilterRule extends RelOptRule {
public abstract class AbstractJoinExtractFilterRule extends RelOptRule
implements TransformationRule {
/** Creates an AbstractJoinExtractFilterRule. */
protected AbstractJoinExtractFilterRule(RelOptRuleOperand operand,
RelBuilderFactory relBuilderFactory, String description) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
* FROM Emp</code>
* </blockquote>
*/
public class AggregateCaseToFilterRule extends RelOptRule {
public class AggregateCaseToFilterRule extends RelOptRule
implements TransformationRule {
public static final AggregateCaseToFilterRule INSTANCE =
new AggregateCaseToFilterRule(RelFactories.LOGICAL_BUILDER, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
* the rule creates separate {@code Aggregate}s and combines using a
* {@link org.apache.calcite.rel.core.Join}.
*/
public final class AggregateExpandDistinctAggregatesRule extends RelOptRule {
public final class AggregateExpandDistinctAggregatesRule extends RelOptRule
implements TransformationRule {
//~ Static fields/initializers ---------------------------------------------

/** The default instance of the rule; operates only on logical expressions. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
* <p>To prevent cycles, this rule will not extract a {@code Project} if the
* {@code Aggregate}s input is already a {@code Project}.
*/
public class AggregateExtractProjectRule extends RelOptRule {
public class AggregateExtractProjectRule extends RelOptRule
implements TransformationRule {

/**
* Creates an AggregateExtractProjectRule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
*
* @see org.apache.calcite.rel.rules.FilterAggregateTransposeRule
*/
public class AggregateFilterTransposeRule extends RelOptRule {
public class AggregateFilterTransposeRule extends RelOptRule
implements TransformationRule {
public static final AggregateFilterTransposeRule INSTANCE =
new AggregateFilterTransposeRule();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
* on s.product_id = pc.product_id</pre></blockquote>
*
*/
public class AggregateJoinJoinRemoveRule extends RelOptRule {
public class AggregateJoinJoinRemoveRule extends RelOptRule
implements TransformationRule {
public static final AggregateJoinJoinRemoveRule INSTANCE =
new AggregateJoinJoinRemoveRule(LogicalAggregate.class,
LogicalJoin.class, RelFactories.LOGICAL_BUILDER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* <pre>select distinct s.product_id from sales as s</pre></blockquote>
*
*/
public class AggregateJoinRemoveRule extends RelOptRule {
public class AggregateJoinRemoveRule extends RelOptRule implements TransformationRule {
public static final AggregateJoinRemoveRule INSTANCE =
new AggregateJoinRemoveRule(LogicalAggregate.class, LogicalJoin.class,
RelFactories.LOGICAL_BUILDER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* {@link org.apache.calcite.rel.core.Aggregate}
* past a {@link org.apache.calcite.rel.core.Join}.
*/
public class AggregateJoinTransposeRule extends RelOptRule {
public class AggregateJoinTransposeRule extends RelOptRule implements TransformationRule {
public static final AggregateJoinTransposeRule INSTANCE =
new AggregateJoinTransposeRule(LogicalAggregate.class, LogicalJoin.class,
RelFactories.LOGICAL_BUILDER, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* MAX of MAX becomes MAX; MIN of MIN becomes MIN. AVG of AVG would not
* match, nor would COUNT of COUNT.
*/
public class AggregateMergeRule extends RelOptRule {
public class AggregateMergeRule extends RelOptRule implements TransformationRule {
public static final AggregateMergeRule INSTANCE =
new AggregateMergeRule();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* <p>In some cases, this rule has the effect of trimming: the aggregate will
* use fewer columns than the project did.
*/
public class AggregateProjectMergeRule extends RelOptRule {
public class AggregateProjectMergeRule extends RelOptRule implements TransformationRule {
public static final AggregateProjectMergeRule INSTANCE =
new AggregateProjectMergeRule(Aggregate.class, Project.class, RelFactories.LOGICAL_BUILDER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
* reduced aggregate. If those constants are not used, another rule will remove
* them from the project.
*/
public class AggregateProjectPullUpConstantsRule extends RelOptRule {
public class AggregateProjectPullUpConstantsRule extends RelOptRule
implements TransformationRule {
//~ Static fields/initializers ---------------------------------------------

/** The singleton. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
* forms like {@code COUNT(x)}, the rule gathers common sub-expressions as it
* goes.
*/
public class AggregateReduceFunctionsRule extends RelOptRule {
public class AggregateReduceFunctionsRule extends RelOptRule
implements TransformationRule {
//~ Static fields/initializers ---------------------------------------------

/** The singleton. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.calcite.plan.RelOptRule;
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.SubstitutionRule;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.Aggregate;
import org.apache.calcite.rel.core.AggregateCall;
Expand Down Expand Up @@ -124,7 +123,7 @@ public void onMatch(RelOptRuleCall call) {
// aggregate functions, add a project for the same effect.
relBuilder.project(relBuilder.fields(aggregate.getGroupSet()));
}
call.getPlanner().setImportance(aggregate, 0d);
call.getPlanner().prune(aggregate);
call.transformTo(relBuilder.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* <p>This pattern indicates that an aggregate table may exist. The rule asks
* the star table for an aggregate table at the required level of aggregation.
*/
public class AggregateStarTableRule extends RelOptRule {
public class AggregateStarTableRule extends RelOptRule implements TransformationRule {
public static final AggregateStarTableRule INSTANCE =
new AggregateStarTableRule(
operandJ(Aggregate.class, null, Aggregate::isSimple,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* {@link org.apache.calcite.rel.core.Union}s
* still have only two inputs.
*/
public class AggregateUnionAggregateRule extends RelOptRule {
public class AggregateUnionAggregateRule extends RelOptRule implements TransformationRule {
/** Instance that matches an {@code Aggregate} as the left input of
* {@code Union}. */
public static final AggregateUnionAggregateRule AGG_ON_FIRST_INPUT =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* {@link org.apache.calcite.rel.core.Aggregate}
* past a non-distinct {@link org.apache.calcite.rel.core.Union}.
*/
public class AggregateUnionTransposeRule extends RelOptRule {
public class AggregateUnionTransposeRule extends RelOptRule implements TransformationRule {
public static final AggregateUnionTransposeRule INSTANCE =
new AggregateUnionTransposeRule(LogicalAggregate.class,
LogicalUnion.class, RelFactories.LOGICAL_BUILDER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.calcite.plan.RelOptRule;
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.SubstitutionRule;
import org.apache.calcite.rel.core.Aggregate;
import org.apache.calcite.rel.core.AggregateCall;
import org.apache.calcite.rel.core.RelFactories;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* {@link org.apache.calcite.rel.logical.LogicalCalc}, but expressed in terms of
* the lower {@link org.apache.calcite.rel.logical.LogicalCalc}'s inputs.
*/
public class CalcMergeRule extends RelOptRule {
public class CalcMergeRule extends RelOptRule implements TransformationRule {
//~ Static fields/initializers ---------------------------------------------

public static final CalcMergeRule INSTANCE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.calcite.plan.RelOptRule;
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.SubstitutionRule;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.rel.logical.LogicalCalc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* specific tasks, such as optimizing before calling an
* {@link org.apache.calcite.interpreter.Interpreter}.
*/
public class CalcSplitRule extends RelOptRule {
public class CalcSplitRule extends RelOptRule implements TransformationRule {
public static final CalcSplitRule INSTANCE =
new CalcSplitRule(RelFactories.LOGICAL_BUILDER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* assist operator implementations which impose requirements on their input
* types.
*/
public class CoerceInputsRule extends RelOptRule {
public class CoerceInputsRule extends RelOptRule implements TransformationRule {
//~ Instance fields --------------------------------------------------------

private final Class consumerRelClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static RexNode replaceTimeUnits(RexBuilder rexBuilder, RexNode e,
/** Rule that converts EXTRACT, FLOOR and CEIL in a {@link Filter} into a date
* range. */
@SuppressWarnings("WeakerAccess")
public static class FilterDateRangeRule extends RelOptRule {
public static class FilterDateRangeRule extends RelOptRule implements TransformationRule {
public FilterDateRangeRule(RelBuilderFactory relBuilderFactory) {
super(operandJ(Filter.class, null, FILTER_PREDICATE, any()),
relBuilderFactory, "FilterDateRangeRule");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.calcite.plan.RelOptPredicateList;
import org.apache.calcite.plan.RelOptRule;
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.SubstitutionRule;
import org.apache.calcite.rel.RelCollation;
import org.apache.calcite.rel.RelCollations;
import org.apache.calcite.rel.RelDistribution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*
* @see org.apache.calcite.rel.rules.AggregateFilterTransposeRule
*/
public class FilterAggregateTransposeRule extends RelOptRule {
public class FilterAggregateTransposeRule extends RelOptRule implements TransformationRule {

/** The default instance of
* {@link FilterAggregateTransposeRule}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @see FilterMergeRule
*/
public class FilterCalcMergeRule extends RelOptRule {
public class FilterCalcMergeRule extends RelOptRule implements TransformationRule {
//~ Static fields/initializers ---------------------------------------------

public static final FilterCalcMergeRule INSTANCE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* Planner rule that pushes a {@link Filter} above a {@link Correlate} into the
* inputs of the Correlate.
*/
public class FilterCorrelateRule extends RelOptRule {
public class FilterCorrelateRule extends RelOptRule implements TransformationRule {

public static final FilterCorrelateRule INSTANCE =
new FilterCorrelateRule(RelFactories.LOGICAL_BUILDER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* Planner rule that pushes filters above and
* within a join node into the join node and/or its children nodes.
*/
public abstract class FilterJoinRule extends RelOptRule {
public abstract class FilterJoinRule extends RelOptRule implements TransformationRule {
/** Predicate that always returns true. With this predicate, every filter
* will be pushed into the ON clause. */
public static final Predicate TRUE_PREDICATE = (join, joinType, exp) -> true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.calcite.plan.Contexts;
import org.apache.calcite.plan.RelOptRule;
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.SubstitutionRule;
import org.apache.calcite.rel.core.Filter;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.tools.RelBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @see org.apache.calcite.rel.rules.ProjectMultiJoinMergeRule
*/
public class FilterMultiJoinMergeRule extends RelOptRule {
public class FilterMultiJoinMergeRule extends RelOptRule implements TransformationRule {
public static final FilterMultiJoinMergeRule INSTANCE =
new FilterMultiJoinMergeRule(RelFactories.LOGICAL_BUILDER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* a {@link org.apache.calcite.rel.core.Filter}
* past a {@link org.apache.calcite.rel.core.Project}.
*/
public class FilterProjectTransposeRule extends RelOptRule {
public class FilterProjectTransposeRule extends RelOptRule implements TransformationRule {
/** The default instance of
* {@link org.apache.calcite.rel.rules.FilterProjectTransposeRule}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
*
* @see org.apache.calcite.sql.fun.SqlStdOperatorTable#IS_NOT_DISTINCT_FROM
*/
public final class FilterRemoveIsNotDistinctFromRule extends RelOptRule {
public final class FilterRemoveIsNotDistinctFromRule extends RelOptRule
implements TransformationRule {
//~ Static fields/initializers ---------------------------------------------

/** The singleton. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* Planner rule that pushes a {@link org.apache.calcite.rel.core.Filter}
* past a {@link org.apache.calcite.rel.core.SetOp}.
*/
public class FilterSetOpTransposeRule extends RelOptRule {
public class FilterSetOpTransposeRule extends RelOptRule implements TransformationRule {
public static final FilterSetOpTransposeRule INSTANCE =
new FilterSetOpTransposeRule(RelFactories.LOGICAL_BUILDER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
* a {@link org.apache.calcite.rel.logical.LogicalFilter}
* past a {@link org.apache.calcite.rel.logical.LogicalTableFunctionScan}.
*/
public class FilterTableFunctionTransposeRule extends RelOptRule {
public class FilterTableFunctionTransposeRule extends RelOptRule
implements TransformationRule {
public static final FilterTableFunctionTransposeRule INSTANCE =
new FilterTableFunctionTransposeRule(RelFactories.LOGICAL_BUILDER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* {@link org.apache.calcite.rel.logical.LogicalFilter} will eventually be
* converted by {@link FilterCalcMergeRule}.
*/
public class FilterToCalcRule extends RelOptRule {
public class FilterToCalcRule extends RelOptRule implements TransformationRule {
//~ Static fields/initializers ---------------------------------------------

public static final FilterToCalcRule INSTANCE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
*
* @see org.apache.calcite.rel.rules.UnionToDistinctRule
*/
public class IntersectToDistinctRule extends RelOptRule {
public class IntersectToDistinctRule extends RelOptRule implements TransformationRule {
public static final IntersectToDistinctRule INSTANCE =
new IntersectToDistinctRule(LogicalIntersect.class, RelFactories.LOGICAL_BUILDER);

Expand Down
Loading