Class AbstractRelOptPlanner

java.lang.Object
org.apache.calcite.plan.AbstractRelOptPlanner
All Implemented Interfaces:
RelOptPlanner
Direct Known Subclasses:
HepPlanner, MockRelOptPlanner, VolcanoPlanner

public abstract class AbstractRelOptPlanner extends Object implements RelOptPlanner
Abstract base for implementations of the RelOptPlanner interface.
  • Field Details

    • mapDescToRule

      protected final Map<String,RelOptRule> mapDescToRule
      Maps rule description to rule, just to ensure that rules' descriptions are unique.
    • costFactory

      protected final RelOptCostFactory costFactory
    • cancelFlag

      protected final AtomicBoolean cancelFlag
    • context

      protected final Context context
      External context. Never null.
  • Constructor Details

    • AbstractRelOptPlanner

      protected AbstractRelOptPlanner(RelOptCostFactory costFactory, @Nullable Context context)
      Creates an AbstractRelOptPlanner.
  • Method Details

    • 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 interface RelOptPlanner
    • getContext

      public Context getContext()
      Description copied from interface: RelOptPlanner
      Provides the Context created when this planner was constructed.
      Specified by:
      getContext in interface RelOptPlanner
      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 creates RelOptCosts.
      Specified by:
      getCostFactory in interface RelOptPlanner
    • setCancelFlag

      public void setCancelFlag(CancelFlag cancelFlag)
      Description copied from interface: RelOptPlanner
      Does nothing.
      Specified by:
      setCancelFlag in interface RelOptPlanner
      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.
    • getRules

      public List<RelOptRule> getRules()
      Description copied from interface: RelOptPlanner
      Returns the list of all registered rules.
      Specified by:
      getRules in interface RelOptPlanner
    • addRule

      public boolean addRule(RelOptRule rule)
      Description copied from interface: RelOptPlanner
      Registers a rule.

      If the rule has already been registered, does nothing. This method determines if the given rule is a ConverterRule and pass the ConverterRule to all registered RelTraitDef instances.

      Specified by:
      addRule in interface RelOptPlanner
      Returns:
      whether the rule was added, as per Collection.add(E)
    • removeRule

      public boolean removeRule(RelOptRule rule)
      Description copied from interface: RelOptPlanner
      Removes a rule.
      Specified by:
      removeRule in interface RelOptPlanner
      Returns:
      true if the rule was present, as per Collection.remove(Object)
    • getRuleByDescription

      protected @Nullable RelOptRule getRuleByDescription(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(@Nullable 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 interface RelOptPlanner
      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 interface RelOptPlanner
    • addMaterialization

      public void addMaterialization(RelOptMaterialization materialization)
      Description copied from interface: RelOptPlanner
      Defines a pair of relational expressions that are equivalent.

      Typically tableRel is a LogicalTableScan representing a table that is a materialized view and queryRel is the SQL expression that populates that view. The intention is that tableRel 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 using tableRel instead.

      Specified by:
      addMaterialization in interface RelOptPlanner
    • getMaterializations

      public List<RelOptMaterialization> getMaterializations()
      Description copied from interface: RelOptPlanner
      Returns the materializations that have been registered with the planner.
      Specified by:
      getMaterializations in interface RelOptPlanner
    • 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 interface RelOptPlanner
    • getLattice

      public @Nullable RelOptLattice getLattice(RelOptTable table)
      Description copied from interface: RelOptPlanner
      Retrieves a lattice, given its star table.
      Specified by:
      getLattice in interface RelOptPlanner
    • 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 interface RelOptPlanner
    • getRelMetadataTimestamp

      @Deprecated public long getRelMetadataTimestamp(RelNode rel)
      Deprecated.
      Description copied from interface: RelOptPlanner
      Gets a timestamp for a given rel's metadata. This timestamp is used by CachingRelMetadataProvider to decide whether cached metadata has gone stale.
      Specified by:
      getRelMetadataTimestamp in interface RelOptPlanner
      Parameters:
      rel - rel of interest
      Returns:
      timestamp of last change which might affect metadata derivation
    • prune

      public void prune(RelNode rel)
      Description copied from interface: RelOptPlanner
      Prunes a node from the planner.

      When a node is pruned, the related pending rule calls are cancelled, and future rules will not fire. This can be used to reduce the search space.

      Specified by:
      prune in interface RelOptPlanner
      Parameters:
      rel - the node to prune.
    • 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 interface RelOptPlanner
      Parameters:
      node - Relational expression
    • onNewClass

      protected void onNewClass(RelNode node)
      Called when a new class of RelNode is seen.
    • 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 interface RelOptPlanner
      Returns:
      Empty trait set
    • getCost

      public @Nullable RelOptCost getCost(RelNode rel, RelMetadataQuery mq)
      Description copied from interface: RelOptPlanner
      Computes the cost of a RelNode. In most cases, this just dispatches to RelMetadataQuery.getCumulativeCost(org.apache.calcite.rel.RelNode).
      Specified by:
      getCost in interface RelOptPlanner
      Parameters:
      rel - Relational expression of interest
      mq - Metadata query
      Returns:
      estimated cost
    • getCost

      @Deprecated public @Nullable RelOptCost getCost(RelNode rel)
      Deprecated.
      Specified by:
      getCost in interface RelOptPlanner
    • addListener

      public void addListener(@UnknownInitialization AbstractRelOptPlanner this, RelOptListener newListener)
      Description copied from interface: RelOptPlanner
      Adds a listener to this planner.
      Specified by:
      addListener in interface RelOptPlanner
      Parameters:
      newListener - new listener to be notified of events
    • registerMetadataProviders

      @Deprecated public void registerMetadataProviders(List<RelMetadataProvider> list)
      Deprecated.
      Description copied from interface: RelOptPlanner
      Gives this planner a chance to register one or more RelMetadataProviders 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 interface RelOptPlanner
      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 the RelTraitDef has already been registered, does nothing.
      Specified by:
      addRelTraitDef in interface RelOptPlanner
      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 interface RelOptPlanner
    • getRelTraitDefs

      public List<RelTraitDef> getRelTraitDefs()
      Description copied from interface: RelOptPlanner
      Returns the list of active trait types.
      Specified by:
      getRelTraitDefs in interface RelOptPlanner
    • setExecutor

      public void setExecutor(@Nullable RexExecutor executor)
      Description copied from interface: RelOptPlanner
      Sets the object that can execute scalar expressions.
      Specified by:
      setExecutor in interface RelOptPlanner
    • getExecutor

      public @Nullable RexExecutor getExecutor()
      Description copied from interface: RelOptPlanner
      Returns the executor used to evaluate constant expressions.
      Specified by:
      getExecutor in interface RelOptPlanner
    • 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 interface RelOptPlanner
    • dumpRuleAttemptsInfo

      protected void dumpRuleAttemptsInfo()
    • 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 call
      newRel - result of transformation
      before - 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, 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

      @Pure public @Nullable RelOptListener getListener()
    • subClasses

      public Iterable<Class<? extends RelNode>> subClasses(Class<? extends RelNode> clazz)
      Returns sub-classes of relational expression.