Class AbstractRelOptPlanner
- java.lang.Object
-
- org.apache.calcite.plan.AbstractRelOptPlanner
-
- All Implemented Interfaces:
RelOptPlanner
- Direct Known Subclasses:
HepPlanner
,VolcanoPlanner
public abstract class AbstractRelOptPlanner extends java.lang.Object implements RelOptPlanner
Abstract base for implementations of theRelOptPlanner
interface.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.calcite.plan.RelOptPlanner
RelOptPlanner.CannotPlanException, RelOptPlanner.Executor
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBoolean
cancelFlag
private java.util.Set<java.lang.Class<? extends RelNode>>
classes
protected Context
context
External context.protected RelOptCostFactory
costFactory
private RexExecutor
executor
private static java.util.regex.Pattern
INTEGER_PATTERN
Regular expression for integer.private MulticastRelOptListener
listener
private java.util.Map<java.lang.String,RelOptRule>
mapDescToRule
Maps rule description to rule, just to ensure that rules' descriptions are unique.private java.util.regex.Pattern
ruleDescExclusionFilter
private java.util.Set<RelTrait>
traits
-
Fields inherited from interface org.apache.calcite.plan.RelOptPlanner
LOGGER
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractRelOptPlanner(RelOptCostFactory costFactory, Context context)
Creates an AbstractRelOptPlanner.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLattice(RelOptLattice lattice)
Defines a lattice.void
addListener(RelOptListener newListener)
Adds a listener to this planner.void
addMaterialization(RelOptMaterialization materialization)
Defines a pair of relational expressions that are equivalent.boolean
addRelTraitDef(RelTraitDef relTraitDef)
Registers a rel trait definition.void
checkCancel()
Checks to see whether cancellation has been requested, and if so, throws an exception.RelOptPlanner
chooseDelegate()
Negotiates an appropriate planner to deal with distributed queries.void
clear()
Removes all internal state, including all registered rules, materialized views, and lattices.void
clearRelTraitDefs()
Clear all the registered RelTraitDef.RelTraitSet
emptyTraitSet()
Creates an empty trait set.protected void
fireRule(RelOptRuleCall ruleCall)
Fires a rule, taking care of tracing and listener notification.Context
getContext()
Provides the Context created when this planner was constructed.RelOptCost
getCost(RelNode rel)
RelOptCost
getCost(RelNode rel, RelMetadataQuery mq)
Computes the cost of a RelNode.RelOptCostFactory
getCostFactory()
Returns the factory that createsRelOptCost
s.RexExecutor
getExecutor()
Returns the executor used to evaluate constant expressions.RelOptLattice
getLattice(RelOptTable table)
Retrieves a lattice, given its star table.protected MulticastRelOptListener
getListener()
java.util.List<RelOptMaterialization>
getMaterializations()
Returns the materializations that have been registered with the planner.long
getRelMetadataTimestamp(RelNode rel)
Gets a timestamp for a given rel's metadata.java.util.List<RelTraitDef>
getRelTraitDefs()
Returns the list of active trait types.protected RelOptRule
getRuleByDescription(java.lang.String description)
Returns the rule with a given descriptionboolean
isRuleExcluded(RelOptRule rule)
Determines whether a given rule is excluded by ruleDescExclusionFilter.protected void
mapRuleDescription(RelOptRule rule)
Registers a rule's description.protected void
notifyChosen(RelNode rel)
Takes care of tracing and listener notification when a rel is chosen as part of the final plan.protected void
notifyDiscard(RelNode rel)
Takes care of tracing and listener notification when a rel is discardedprotected void
notifyEquivalence(RelNode rel, java.lang.Object equivalenceClass, boolean physical)
Takes care of tracing and listener notification when a rel equivalence is detected.protected void
notifyTransformation(RelOptRuleCall ruleCall, RelNode newRel, boolean before)
Takes care of tracing and listener notification when a rule's transformation is applied.void
onCopy(RelNode rel, RelNode newRel)
Called when a relational expression is copied to a similar expression.protected void
onNewClass(RelNode node)
Called when a new class ofRelNode
is seen.void
registerClass(RelNode node)
Registers a class of RelNode.void
registerMetadataProviders(java.util.List<RelMetadataProvider> list)
Gives this planner a chance to register one or moreRelMetadataProvider
s in the chain which will be used to answer metadata queries.void
registerSchema(RelOptSchema schema)
Tells this planner that a schema exists.void
setCancelFlag(CancelFlag cancelFlag)
Does nothing.void
setExecutor(RexExecutor executor)
Sets the object that can execute scalar expressions.void
setImportance(RelNode rel, double importance)
Sets the importance of a relational expression.void
setRuleDescExclusionFilter(java.util.regex.Pattern exclusionFilter)
Sets the exclusion filter to use for this planner.java.lang.Iterable<java.lang.Class<? extends RelNode>>
subClasses(java.lang.Class<? extends RelNode> clazz)
Returns sub-classes of relational expression.protected void
unmapRuleDescription(RelOptRule rule)
Removes the mapping between a rule and its description.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.calcite.plan.RelOptPlanner
addRule, changeTraits, ensureRegistered, findBestExp, getRoot, getRules, isRegistered, register, removeRule, setRoot
-
-
-
-
Field Detail
-
INTEGER_PATTERN
private static final java.util.regex.Pattern INTEGER_PATTERN
Regular expression for integer.
-
mapDescToRule
private final java.util.Map<java.lang.String,RelOptRule> mapDescToRule
Maps rule description to rule, just to ensure that rules' descriptions are unique.
-
costFactory
protected final RelOptCostFactory costFactory
-
listener
private MulticastRelOptListener listener
-
ruleDescExclusionFilter
private java.util.regex.Pattern ruleDescExclusionFilter
-
cancelFlag
private final java.util.concurrent.atomic.AtomicBoolean cancelFlag
-
classes
private final java.util.Set<java.lang.Class<? extends RelNode>> classes
-
traits
private final java.util.Set<RelTrait> traits
-
context
protected final Context context
External context. Never null.
-
executor
private RexExecutor executor
-
-
Constructor Detail
-
AbstractRelOptPlanner
protected AbstractRelOptPlanner(RelOptCostFactory costFactory, Context context)
Creates an AbstractRelOptPlanner.
-
-
Method Detail
-
clear
public void clear()
Description copied from interface:RelOptPlanner
Removes all internal state, including all registered rules, materialized views, and lattices.- Specified by:
clear
in interfaceRelOptPlanner
-
getContext
public Context getContext()
Description copied from interface:RelOptPlanner
Provides the Context created when this planner was constructed.- Specified by:
getContext
in interfaceRelOptPlanner
- Returns:
- Never null; either an externally defined context, or a dummy context that returns null for each requested interface
-
getCostFactory
public RelOptCostFactory getCostFactory()
Description copied from interface:RelOptPlanner
Returns the factory that createsRelOptCost
s.- Specified by:
getCostFactory
in interfaceRelOptPlanner
-
setCancelFlag
public void setCancelFlag(CancelFlag cancelFlag)
Description copied from interface:RelOptPlanner
Does nothing.- Specified by:
setCancelFlag
in interfaceRelOptPlanner
- Parameters:
cancelFlag
- flag which the planner should periodically check
-
checkCancel
public void checkCancel()
Checks to see whether cancellation has been requested, and if so, throws an exception.
-
mapRuleDescription
protected void mapRuleDescription(RelOptRule rule)
Registers a rule's description.- Parameters:
rule
- Rule
-
unmapRuleDescription
protected void unmapRuleDescription(RelOptRule rule)
Removes the mapping between a rule and its description.- Parameters:
rule
- Rule
-
getRuleByDescription
protected RelOptRule getRuleByDescription(java.lang.String description)
Returns the rule with a given description- Parameters:
description
- Description- Returns:
- Rule with given description, or null if not found
-
setRuleDescExclusionFilter
public void setRuleDescExclusionFilter(java.util.regex.Pattern exclusionFilter)
Description copied from interface:RelOptPlanner
Sets the exclusion filter to use for this planner. Rules which match the given pattern will not be fired regardless of whether or when they are added to the planner.- Specified by:
setRuleDescExclusionFilter
in interfaceRelOptPlanner
- Parameters:
exclusionFilter
- pattern to match for exclusion; null to disable filtering
-
isRuleExcluded
public boolean isRuleExcluded(RelOptRule rule)
Determines whether a given rule is excluded by ruleDescExclusionFilter.- Parameters:
rule
- rule to test- Returns:
- true iff rule should be excluded
-
chooseDelegate
public RelOptPlanner chooseDelegate()
Description copied from interface:RelOptPlanner
Negotiates an appropriate planner to deal with distributed queries. The idea is that the schemas decide among themselves which has the most knowledge. Right now, the local planner retains control.- Specified by:
chooseDelegate
in interfaceRelOptPlanner
-
addMaterialization
public void addMaterialization(RelOptMaterialization materialization)
Description copied from interface:RelOptPlanner
Defines a pair of relational expressions that are equivalent.Typically
tableRel
is aLogicalTableScan
representing a table that is a materialized view andqueryRel
is the SQL expression that populates that view. The intention is thattableRel
is cheaper to evaluate and therefore if the query being optimized uses (or can be rewritten to use)queryRel
as a sub-expression then it can be optimized by usingtableRel
instead.- Specified by:
addMaterialization
in interfaceRelOptPlanner
-
getMaterializations
public java.util.List<RelOptMaterialization> getMaterializations()
Description copied from interface:RelOptPlanner
Returns the materializations that have been registered with the planner.- Specified by:
getMaterializations
in interfaceRelOptPlanner
-
addLattice
public void addLattice(RelOptLattice lattice)
Description copied from interface:RelOptPlanner
Defines a lattice.The lattice may have materializations; it is not necessary to call
RelOptPlanner.addMaterialization(org.apache.calcite.plan.RelOptMaterialization)
for these; they are registered implicitly.- Specified by:
addLattice
in interfaceRelOptPlanner
-
getLattice
public RelOptLattice getLattice(RelOptTable table)
Description copied from interface:RelOptPlanner
Retrieves a lattice, given its star table.- Specified by:
getLattice
in interfaceRelOptPlanner
-
registerSchema
public void registerSchema(RelOptSchema schema)
Description copied from interface:RelOptPlanner
Tells this planner that a schema exists. This is the schema's chance to tell the planner about all of the special transformation rules.- Specified by:
registerSchema
in interfaceRelOptPlanner
-
getRelMetadataTimestamp
public long getRelMetadataTimestamp(RelNode rel)
Description copied from interface:RelOptPlanner
Gets a timestamp for a given rel's metadata. This timestamp is used byCachingRelMetadataProvider
to decide whether cached metadata has gone stale.- Specified by:
getRelMetadataTimestamp
in interfaceRelOptPlanner
- Parameters:
rel
- rel of interest- Returns:
- timestamp of last change which might affect metadata derivation
-
setImportance
public void setImportance(RelNode rel, double importance)
Description copied from interface:RelOptPlanner
Sets the importance of a relational expression.An important use of this method is when a
RelOptRule
has created a relational expression which is indisputably better than the original relational expression. The rule set the original relational expression's importance to zero, to reduce the search space. Pending rule calls are cancelled, and future rules will not fire.- Specified by:
setImportance
in interfaceRelOptPlanner
- Parameters:
rel
- Relational expressionimportance
- Importance
-
registerClass
public void registerClass(RelNode node)
Description copied from interface:RelOptPlanner
Registers a class of RelNode. If this class of RelNode has been seen before, does nothing.- Specified by:
registerClass
in interfaceRelOptPlanner
- Parameters:
node
- Relational expression
-
emptyTraitSet
public RelTraitSet emptyTraitSet()
Description copied from interface:RelOptPlanner
Creates an empty trait set. It contains all registered traits, and the default values of any traits that have them.The empty trait set acts as the prototype (a kind of factory) for all subsequently created trait sets.
- Specified by:
emptyTraitSet
in interfaceRelOptPlanner
- Returns:
- Empty trait set
-
getCost
public RelOptCost getCost(RelNode rel, RelMetadataQuery mq)
Description copied from interface:RelOptPlanner
Computes the cost of a RelNode. In most cases, this just dispatches toRelMetadataQuery.getCumulativeCost(org.apache.calcite.rel.RelNode)
.- Specified by:
getCost
in interfaceRelOptPlanner
- Parameters:
rel
- Relational expression of interestmq
- Metadata query- Returns:
- estimated cost
-
getCost
public RelOptCost getCost(RelNode rel)
- Specified by:
getCost
in interfaceRelOptPlanner
-
addListener
public void addListener(RelOptListener newListener)
Description copied from interface:RelOptPlanner
Adds a listener to this planner.- Specified by:
addListener
in interfaceRelOptPlanner
- Parameters:
newListener
- new listener to be notified of events
-
registerMetadataProviders
public void registerMetadataProviders(java.util.List<RelMetadataProvider> list)
Description copied from interface:RelOptPlanner
Gives this planner a chance to register one or moreRelMetadataProvider
s in the chain which will be used to answer metadata queries.Planners which use their own relational expressions internally to represent concepts such as equivalence classes will generally need to supply corresponding metadata providers.
- Specified by:
registerMetadataProviders
in interfaceRelOptPlanner
- Parameters:
list
- receives planner's custom providers, if any
-
addRelTraitDef
public boolean addRelTraitDef(RelTraitDef relTraitDef)
Description copied from interface:RelOptPlanner
Registers a rel trait definition. If theRelTraitDef
has already been registered, does nothing.- Specified by:
addRelTraitDef
in interfaceRelOptPlanner
- Returns:
- whether the RelTraitDef was added, as per
Collection.add(E)
-
clearRelTraitDefs
public void clearRelTraitDefs()
Description copied from interface:RelOptPlanner
Clear all the registered RelTraitDef.- Specified by:
clearRelTraitDefs
in interfaceRelOptPlanner
-
getRelTraitDefs
public java.util.List<RelTraitDef> getRelTraitDefs()
Description copied from interface:RelOptPlanner
Returns the list of active trait types.- Specified by:
getRelTraitDefs
in interfaceRelOptPlanner
-
setExecutor
public void setExecutor(RexExecutor executor)
Description copied from interface:RelOptPlanner
Sets the object that can execute scalar expressions.- Specified by:
setExecutor
in interfaceRelOptPlanner
-
getExecutor
public RexExecutor getExecutor()
Description copied from interface:RelOptPlanner
Returns the executor used to evaluate constant expressions.- Specified by:
getExecutor
in interfaceRelOptPlanner
-
onCopy
public void onCopy(RelNode rel, RelNode newRel)
Description copied from interface:RelOptPlanner
Called when a relational expression is copied to a similar expression.- Specified by:
onCopy
in interfaceRelOptPlanner
-
fireRule
protected void fireRule(RelOptRuleCall ruleCall)
Fires a rule, taking care of tracing and listener notification.- Parameters:
ruleCall
- description of rule call
-
notifyTransformation
protected void notifyTransformation(RelOptRuleCall ruleCall, RelNode newRel, boolean before)
Takes care of tracing and listener notification when a rule's transformation is applied.- Parameters:
ruleCall
- description of rule callnewRel
- result of transformationbefore
- true before registration of new rel; false after
-
notifyChosen
protected void notifyChosen(RelNode rel)
Takes care of tracing and listener notification when a rel is chosen as part of the final plan.- Parameters:
rel
- chosen rel
-
notifyEquivalence
protected void notifyEquivalence(RelNode rel, java.lang.Object equivalenceClass, boolean physical)
Takes care of tracing and listener notification when a rel equivalence is detected.- Parameters:
rel
- chosen rel
-
notifyDiscard
protected void notifyDiscard(RelNode rel)
Takes care of tracing and listener notification when a rel is discarded- Parameters:
rel
- discarded rel
-
getListener
protected MulticastRelOptListener getListener()
-
-