public abstract class RelOptRule extends Object
RelOptRule transforms an expression into another. It has a
list of RelOptRuleOperands, which determine whether the rule can be
applied to a particular section of the tree.
The optimizer figures out which rules are applicable, then calls
onMatch(org.apache.calcite.plan.RelOptRuleCall) on each of them.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
RelOptRule.ConverterRelOptRuleOperand
Operand to an instance of the converter rule.
|
| Modifier and Type | Field and Description |
|---|---|
protected String |
description
Description of rule, must be unique within planner.
|
List<RelOptRuleOperand> |
operands
Flattened list of operands.
|
RelBuilderFactory |
relBuilderFactory
Factory for a builder for relational expressions.
|
| Modifier | Constructor and Description |
|---|---|
protected |
RelOptRule(RelOptRuleOperand operand)
Creates a rule.
|
protected |
RelOptRule(RelOptRuleOperand operand,
RelBuilderFactory relBuilderFactory,
@Nullable String description)
Creates a rule with an explicit description.
|
protected |
RelOptRule(RelOptRuleOperand operand,
String description)
Creates a rule with an explicit description.
|
| Modifier and Type | Method and Description |
|---|---|
static RelOptRuleOperandChildren |
any()
Deprecated.
|
static RelNode |
convert(RelNode rel,
@Nullable RelTrait toTrait)
Converts one trait of a relational expression, if it does not
already have that trait.
|
static RelNode |
convert(RelNode rel,
RelTraitSet toTraits)
Converts a relation expression to a given set of traits, if it does not
already have those traits.
|
protected static List<RelNode> |
convertList(List<RelNode> rels,
RelTrait trait)
Converts a list of relational expressions.
|
protected static <R extends RelNode> |
convertOperand(Class<R> clazz,
Predicate<? super R> predicate,
RelTrait trait)
Deprecated.
|
protected static <R extends RelNode> |
convertOperand(Class<R> clazz,
com.google.common.base.Predicate<? super R> predicate,
RelTrait trait)
Deprecated.
|
boolean |
equals(@Nullable Object obj) |
protected boolean |
equals(RelOptRule that)
Returns whether this rule is equal to another rule.
|
RelOptRuleOperand |
getOperand()
Returns the root operand of this rule.
|
List<RelOptRuleOperand> |
getOperands()
Returns a flattened list of operands of this rule.
|
@Nullable Convention |
getOutConvention()
Returns the convention of the result of firing this rule, null if
not known.
|
@Nullable RelTrait |
getOutTrait()
Returns the trait which will be modified as a result of firing this rule,
or null if the rule is not a converter rule.
|
int |
hashCode() |
boolean |
matches(RelOptRuleCall call)
Returns whether this rule could possibly match the given operands.
|
static RelOptRuleOperandChildren |
none()
Deprecated.
|
abstract void |
onMatch(RelOptRuleCall call)
Receives notification about a rule match.
|
static <R extends RelNode> |
operand(Class<R> clazz,
RelOptRuleOperandChildren operandList)
Deprecated.
|
static <R extends RelNode> |
operand(Class<R> clazz,
RelOptRuleOperand first,
RelOptRuleOperand... rest)
Deprecated.
|
static <R extends RelNode> |
operand(Class<R> clazz,
RelTrait trait,
com.google.common.base.Predicate<? super R> predicate,
RelOptRuleOperandChildren operandList)
|
static <R extends RelNode> |
operand(Class<R> clazz,
RelTrait trait,
com.google.common.base.Predicate<? super R> predicate,
RelOptRuleOperand first,
RelOptRuleOperand... rest)
Deprecated.
|
static <R extends RelNode> |
operand(Class<R> clazz,
RelTrait trait,
RelOptRuleOperandChildren operandList)
Deprecated.
|
static <R extends RelNode> |
operandJ(Class<R> clazz,
RelTrait trait,
Predicate<? super R> predicate,
RelOptRuleOperandChildren operandList)
Deprecated.
|
static <R extends RelNode> |
operandJ(Class<R> clazz,
RelTrait trait,
Predicate<? super R> predicate,
RelOptRuleOperand first,
RelOptRuleOperand... rest)
Deprecated.
|
static RelOptRuleOperandChildren |
some(RelOptRuleOperand first,
RelOptRuleOperand... rest)
|
String |
toString()
Returns the description of this rule.
|
static RelOptRuleOperandChildren |
unordered(RelOptRuleOperand first,
RelOptRuleOperand... rest)
Deprecated.
|
protected final String description
public final RelBuilderFactory relBuilderFactory
The actual builder is available via RelOptRuleCall.builder().
public final List<RelOptRuleOperand> operands
protected RelOptRule(RelOptRuleOperand operand)
operand - root operand, must not be nullprotected RelOptRule(RelOptRuleOperand operand, String description)
operand - root operand, must not be nulldescription - Description, or null to guess descriptionprotected RelOptRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, @Nullable String description)
operand - root operand, must not be nulldescription - Description, or null to guess descriptionrelBuilderFactory - Builder for relational expressions@Deprecated public static <R extends RelNode> RelOptRuleOperand operand(Class<R> clazz, RelOptRuleOperandChildren operandList)
RelRule.OperandBuilder.operand(Class)R - Class of relational expression to matchclazz - Class of relational expression to match (must not be null)operandList - Child operands@Deprecated public static <R extends RelNode> RelOptRuleOperand operand(Class<R> clazz, RelTrait trait, RelOptRuleOperandChildren operandList)
RelRule.OperandBuilder.operand(Class)R - Class of relational expression to matchclazz - Class of relational expression to match (must not be null)trait - Trait to match, or null to match any traitoperandList - Child operands@Deprecated public static <R extends RelNode> RelOptRuleOperand operandJ(Class<R> clazz, RelTrait trait, Predicate<? super R> predicate, RelOptRuleOperandChildren operandList)
RelRule.OperandBuilder.operand(Class)R - Class of relational expression to matchclazz - Class of relational expression to match (must not be null)trait - Trait to match, or null to match any traitpredicate - Additional match predicateoperandList - Child operands@Deprecated public static <R extends RelNode> RelOptRuleOperand operand(Class<R> clazz, RelTrait trait, com.google.common.base.Predicate<? super R> predicate, RelOptRuleOperandChildren operandList)
@Deprecated public static <R extends RelNode> RelOptRuleOperand operandJ(Class<R> clazz, RelTrait trait, Predicate<? super R> predicate, RelOptRuleOperand first, RelOptRuleOperand... rest)
RelRule.OperandBuilder.operand(Class)R - Class of relational expression to matchclazz - Class of relational expression to match (must not be null)trait - Trait to match, or null to match any traitpredicate - Additional match predicatefirst - First operandrest - Rest operands@Deprecated public static <R extends RelNode> RelOptRuleOperand operand(Class<R> clazz, RelTrait trait, com.google.common.base.Predicate<? super R> predicate, RelOptRuleOperand first, RelOptRuleOperand... rest)
@Deprecated public static <R extends RelNode> RelOptRuleOperand operand(Class<R> clazz, RelOptRuleOperand first, RelOptRuleOperand... rest)
RelRule.OperandBuilder.operand(Class)Shorthand for operand(clazz, some(...)).
If you wish to match a relational expression that has no children
(that is, a leaf node), write operand(clazz, none())
If you wish to match a relational expression that has any number of
children, write operand(clazz, any())
R - Class of relational expression to matchclazz - Class of relational expression to match (must not be null)first - First operandrest - Rest operands@Deprecated protected static <R extends RelNode> RelOptRule.ConverterRelOptRuleOperand convertOperand(Class<R> clazz, Predicate<? super R> predicate, RelTrait trait)
clazz - Class of relational expression to match (must not be null)trait - Trait to match, or null to match any traitpredicate - Predicate to apply to relational expression@Deprecated protected static <R extends RelNode> RelOptRule.ConverterRelOptRuleOperand convertOperand(Class<R> clazz, com.google.common.base.Predicate<? super R> predicate, RelTrait trait)
convertOperand(Class, Predicate, RelTrait).@Deprecated public static RelOptRuleOperandChildren some(RelOptRuleOperand first, RelOptRuleOperand... rest)
RelRule.OperandDetailBuilder.inputs(org.apache.calcite.plan.RelRule.OperandTransform...)first - First child operandrest - Remaining child operands (may be empty)@Deprecated public static RelOptRuleOperandChildren unordered(RelOptRuleOperand first, RelOptRuleOperand... rest)
This is useful when matching a relational expression which can have a variable number of children. For example, the rule to eliminate empty children of a Union would have operands
Operand(Union, true, Operand(Empty))
and given the relational expressions
Union(LogicalFilter, Empty, LogicalProject)
would fire the rule with arguments
{Union, Empty}
It is up to the rule to deduce the other children, or indeed the position of the matched child.
first - First child operandrest - Remaining child operands (may be empty)@Deprecated public static RelOptRuleOperandChildren none()
RelRule.OperandDetailBuilder.noInputs()@Deprecated public static RelOptRuleOperandChildren any()
RelRule.OperandDetailBuilder.anyInputs()public RelOptRuleOperand getOperand()
public List<RelOptRuleOperand> getOperands()
protected boolean equals(RelOptRule that)
The base implementation checks that the rules have the same class and that the operands are equal; derived classes can override.
that - Another rulepublic boolean matches(RelOptRuleCall call)
This method is an opportunity to apply side-conditions to a rule. The
RelOptPlanner calls this method after matching all operands of
the rule, and before calling onMatch(RelOptRuleCall).
In implementations of RelOptPlanner which may queue up a
matched RelOptRuleCall for a long time before calling
onMatch(RelOptRuleCall), this method is beneficial because it
allows the planner to discard rules earlier in the process.
The default implementation of this method returns true.
It is acceptable for any implementation of this method to give a false
positives, that is, to say that the rule matches the operands but have
onMatch(RelOptRuleCall) subsequently not generate any
successors.
The following script is useful to identify rules which commonly produce no successors. You should override this method for these rules:
awk ' /Apply rule/ {rule=$4; ruleCount[rule]++;} /generated 0 successors/ {ruleMiss[rule]++;} END { printf "%-30s %s %s\n", "Rule", "Fire", "Miss"; for (i in ruleCount) { printf "%-30s %5d %5d\n", i, ruleCount[i], ruleMiss[i]; } } ' FarragoTrace.log
call - Rule call which has been determined to match all operands of
this rulepublic abstract void onMatch(RelOptRuleCall call)
call.rels holds the set of relational
expressions which match the operands to the rule;
call.rels[0] is the root expression.
Typically a rule would check that the nodes are valid matches, creates
a new expression, then calls back RelOptRuleCall.transformTo(org.apache.calcite.rel.RelNode, java.util.Map<org.apache.calcite.rel.RelNode, org.apache.calcite.rel.RelNode>, org.apache.calcite.plan.RelHintsPropagator) to
register the expression.
call - Rule callmatches(RelOptRuleCall)public @Nullable Convention getOutConvention()
public @Nullable RelTrait getOutTrait()
public final String toString()
It must be unique (for rules that are not equal) and must consist of only the characters A-Z, a-z, 0-9, '_', '.', '(', ')', '-', ',', '[', ']', ':', ' '. It must start with a letter.
public static RelNode convert(RelNode rel, RelTraitSet toTraits)
rel - Relational expression to converttoTraits - desired traitspublic static RelNode convert(RelNode rel, @Nullable RelTrait toTrait)
rel - Relational expression to converttoTrait - Desired traitCopyright © 2012-2022 Apache Software Foundation. All Rights Reserved.