Package org.apache.calcite.plan
Class RelTraitDef<T extends RelTrait>
- java.lang.Object
-
- org.apache.calcite.plan.RelTraitDef<T>
-
- Type Parameters:
T
- Trait that this trait definition is based upon
- Direct Known Subclasses:
ConventionTraitDef
,RelCollationTraitDef
,RelDistributionTraitDef
public abstract class RelTraitDef<T extends RelTrait> extends java.lang.Object
RelTraitDef represents a class ofRelTrait
s. Implementations of RelTraitDef may be singletons under the following conditions:- if the set of all possible associated RelTraits is finite and fixed (e.g. all RelTraits for this RelTraitDef are known at compile time). For example, the CallingConvention trait meets this requirement, because CallingConvention is effectively an enumeration.
- Either
-
canConvert(RelOptPlanner, RelTrait, RelTrait)
andconvert(RelOptPlanner, RelNode, RelTrait, boolean)
do not require planner-instance-specific information, or - the RelTraitDef manages separate sets of conversion data internally. See
ConventionTraitDef
for an example of this.
-
Otherwise, a new instance of RelTraitDef must be constructed and registered with each new planner instantiated.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RelTraitDef()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
canConvert(RelOptPlanner planner, T fromTrait, T toTrait)
Tests whether the given RelTrait can be converted to another RelTrait.boolean
canConvert(RelOptPlanner planner, T fromTrait, T toTrait, RelNode fromRel)
Tests whether the given RelTrait can be converted to another RelTrait.T
canonize(T trait)
Takes an arbitrary RelTrait and returns the canonical representation of that RelTrait.abstract RelNode
convert(RelOptPlanner planner, RelNode rel, T toTrait, boolean allowInfiniteCostConverters)
Converts the given RelNode to the given RelTrait.void
deregisterConverterRule(RelOptPlanner planner, ConverterRule converterRule)
Provides notification that a particularConverterRule
has been de-registered from aRelOptPlanner
.abstract T
getDefault()
Returns the default member of this trait.abstract java.lang.String
getSimpleName()
abstract java.lang.Class<T>
getTraitClass()
boolean
multiple()
Whether a relational expression may possess more than one instance of this trait simultaneously.void
registerConverterRule(RelOptPlanner planner, ConverterRule converterRule)
Provides notification of the registration of a particularConverterRule
with aRelOptPlanner
.
-
-
-
Method Detail
-
multiple
public boolean multiple()
Whether a relational expression may possess more than one instance of this trait simultaneously.A subset has only one instance of a trait.
-
getTraitClass
public abstract java.lang.Class<T> getTraitClass()
- Returns:
- the specific RelTrait type associated with this RelTraitDef.
-
getSimpleName
public abstract java.lang.String getSimpleName()
- Returns:
- a simple name for this RelTraitDef (for use in
RelNode.explain(org.apache.calcite.rel.RelWriter)
).
-
canonize
public final T canonize(T trait)
Takes an arbitrary RelTrait and returns the canonical representation of that RelTrait. Canonized RelTrait objects may always be compared using the equality operator (==
).If an equal RelTrait has already been canonized and is still in use, it will be returned. Otherwise, the given RelTrait is made canonical and returned.
- Parameters:
trait
- a possibly non-canonical RelTrait- Returns:
- a canonical RelTrait.
-
convert
public abstract RelNode convert(RelOptPlanner planner, RelNode rel, T toTrait, boolean allowInfiniteCostConverters)
Converts the given RelNode to the given RelTrait.- Parameters:
planner
- the planner requesting the conversionrel
- RelNode to converttoTrait
- RelTrait to convert toallowInfiniteCostConverters
- flag indicating whether infinite cost converters are allowed- Returns:
- a converted RelNode or null if conversion is not possible
-
canConvert
public abstract boolean canConvert(RelOptPlanner planner, T fromTrait, T toTrait)
Tests whether the given RelTrait can be converted to another RelTrait.- Parameters:
planner
- the planner requesting the conversion testfromTrait
- the RelTrait to convert fromtoTrait
- the RelTrait to convert to- Returns:
- true if fromTrait can be converted to toTrait
-
canConvert
public boolean canConvert(RelOptPlanner planner, T fromTrait, T toTrait, RelNode fromRel)
Tests whether the given RelTrait can be converted to another RelTrait.- Parameters:
planner
- the planner requesting the conversion testfromTrait
- the RelTrait to convert fromtoTrait
- the RelTrait to convert tofromRel
- the RelNode to convert from (with fromTrait)- Returns:
- true if fromTrait can be converted to toTrait
-
registerConverterRule
public void registerConverterRule(RelOptPlanner planner, ConverterRule converterRule)
Provides notification of the registration of a particularConverterRule
with aRelOptPlanner
. The default implementation does nothing.- Parameters:
planner
- the planner registering the ruleconverterRule
- the registered converter rule
-
deregisterConverterRule
public void deregisterConverterRule(RelOptPlanner planner, ConverterRule converterRule)
Provides notification that a particularConverterRule
has been de-registered from aRelOptPlanner
. The default implementation does nothing.- Parameters:
planner
- the planner registering the ruleconverterRule
- the registered converter rule
-
getDefault
public abstract T getDefault()
Returns the default member of this trait.
-
-