Class AbstractRelNode

java.lang.Object
org.apache.calcite.rel.AbstractRelNode
All Implemented Interfaces:
Cloneable, RelOptNode, RelNode
Direct Known Subclasses:
BiRel, DruidQuery, HepRelVertex, MultiJoin, RelSubset, SetOp, SingleRel, TableFunctionScan, TableScan, Values

public abstract class AbstractRelNode extends Object implements RelNode
Base class for every relational expression (RelNode).
  • Field Details

    • rowType

      protected @MonotonicNonNull RelDataType rowType
      Cached type of this relational expression.
    • digest

      @API(since="1.24", status=INTERNAL) protected final RelDigest digest
      The digest that uniquely identifies the node.
    • id

      protected final int id
      Unique id of this object, for debugging.
    • traitSet

      protected final RelTraitSet traitSet
      RelTraitSet that describes the traits of this RelNode.
  • Constructor Details

  • Method Details

    • copy

      public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs)
      Description copied from interface: RelNode
      Creates a copy of this relational expression, perhaps changing traits and inputs.

      Sub-classes with other important attributes are encouraged to create variants of this method with more parameters.

      Specified by:
      copy in interface RelNode
      Parameters:
      traitSet - Trait set
      inputs - Inputs
      Returns:
      Copy of this relational expression, substituting traits and inputs
    • sole

      protected static <T> T sole(List<T> collection)
    • getCluster

      public final RelOptCluster getCluster()
      Description copied from interface: RelOptNode
      Returns the cluster this relational expression belongs to.
      Specified by:
      getCluster in interface RelOptNode
      Returns:
      cluster
    • getConvention

      @Pure public final @Nullable Convention getConvention(@UnknownInitialization AbstractRelNode this)
      Description copied from interface: RelNode
      Return the CallingConvention trait from this RelNode's trait set.
      Specified by:
      getConvention in interface RelNode
      Returns:
      this RelNode's CallingConvention
    • getTraitSet

      public RelTraitSet getTraitSet()
      Description copied from interface: RelOptNode
      Retrieves this RelNode's traits. Note that although the RelTraitSet returned is modifiable, it must not be modified during optimization. It is legal to modify the traits of a RelNode before or after optimization, although doing so could render a tree of RelNodes unimplementable. If a RelNode's traits need to be modified during optimization, clone the RelNode and change the clone's traits.
      Specified by:
      getTraitSet in interface RelOptNode
      Returns:
      this RelNode's trait set
    • getCorrelVariable

      public @Nullable String getCorrelVariable()
      Description copied from interface: RelNode
      Returns the name of the variable which is to be implicitly set at runtime each time a row is returned from the first input of this relational expression; or null if there is no variable.
      Specified by:
      getCorrelVariable in interface RelNode
      Returns:
      Name of correlating variable, or null
    • getId

      public int getId()
      Description copied from interface: RelOptNode
      Returns the ID of this relational expression, unique among all relational expressions created since the server was started.
      Specified by:
      getId in interface RelOptNode
      Returns:
      Unique ID
    • getInput

      public RelNode getInput(int i)
      Description copied from interface: RelNode
      Returns the ith input relational expression.
      Specified by:
      getInput in interface RelNode
      Parameters:
      i - Ordinal of input
      Returns:
      ith input
    • register

      public void register(RelOptPlanner planner)
      Description copied from interface: RelNode
      Registers any special rules specific to this kind of relational expression.

      The planner calls this method this first time that it sees a relational expression of this class. The derived class should call RelOptPlanner.addRule(org.apache.calcite.plan.RelOptRule) for each rule, and then call super.register.

      Specified by:
      register in interface RelNode
      Parameters:
      planner - Planner to be used to register additional relational expressions
    • getRelTypeName

      public String getRelTypeName()
      Description copied from interface: RelNode
      Returns the name of this relational expression's class, sans package name, for use in explain. For example, for a org.apache.calcite.rel.ArrayRel.ArrayReader, this method returns "ArrayReader".
      Specified by:
      getRelTypeName in interface RelNode
      Returns:
      Name of this relational expression's class, sans package name, for use in explain
    • isValid

      public boolean isValid(Litmus litmus, @Nullable RelNode.Context context)
      Description copied from interface: RelNode
      Returns whether this relational expression is valid.

      If assertions are enabled, this method is typically called with litmus = THROW, as follows:

      assert rel.isValid(Litmus.THROW)

      This signals that the method can throw an AssertionError if it is not valid.

      Specified by:
      isValid in interface RelNode
      Parameters:
      litmus - What to do if invalid
      context - Context for validity checking
      Returns:
      Whether relational expression is valid
    • getRowType

      public final RelDataType getRowType()
      Description copied from interface: RelNode
      Returns the type of the rows returned by this relational expression.
      Specified by:
      getRowType in interface RelNode
      Specified by:
      getRowType in interface RelOptNode
    • deriveRowType

      protected RelDataType deriveRowType()
    • getExpectedInputRowType

      public RelDataType getExpectedInputRowType(int ordinalInParent)
      Description copied from interface: RelNode
      Returns the type of the rows expected for an input. Defaults to RelNode.getRowType().
      Specified by:
      getExpectedInputRowType in interface RelNode
      Parameters:
      ordinalInParent - input's 0-based ordinal with respect to this parent rel
      Returns:
      expected row type
    • getInputs

      public List<RelNode> getInputs()
      Description copied from interface: RelNode
      Returns an array of this relational expression's inputs. If there are no inputs, returns an empty list, not null.
      Specified by:
      getInputs in interface RelNode
      Specified by:
      getInputs in interface RelOptNode
      Returns:
      Array of this relational expression's inputs
    • estimateRowCount

      public double estimateRowCount(RelMetadataQuery mq)
      Description copied from interface: RelNode
      Returns an estimate of the number of rows this relational expression will return.

      NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use RelMetadataQuery.getRowCount(org.apache.calcite.rel.RelNode), which gives plugins a chance to override the rel's default ideas about row count.

      Specified by:
      estimateRowCount in interface RelNode
      Parameters:
      mq - Metadata query
      Returns:
      Estimate of the number of rows this relational expression will return
    • getVariablesSet

      public Set<CorrelationId> getVariablesSet()
      Description copied from interface: RelNode
      Returns the variables that are set in this relational expression but also used and therefore not available to parents of this relational expression.
      Specified by:
      getVariablesSet in interface RelNode
      Returns:
      Names of variables which are set in this relational expression
    • collectVariablesUsed

      public void collectVariablesUsed(Set<CorrelationId> variableSet)
      Description copied from interface: RelNode
      Collects variables known to be used by this expression or its descendants. By default, no such information is available and must be derived by analyzing sub-expressions, but some optimizer implementations may insert special expressions which remember such information.
      Specified by:
      collectVariablesUsed in interface RelNode
      Parameters:
      variableSet - receives variables used
    • isEnforcer

      public boolean isEnforcer()
      Description copied from interface: RelNode
      Indicates whether it is an enforcer operator, e.g. PhysicalSort, PhysicalHashDistribute, etc. As an enforcer, the operator must be created only when required traitSet is not satisfied by its input.
      Specified by:
      isEnforcer in interface RelNode
      Returns:
      Whether it is an enforcer operator
    • collectVariablesSet

      public void collectVariablesSet(Set<CorrelationId> variableSet)
      Description copied from interface: RelNode
      Collects variables set by this expression. TODO: is this required?
      Specified by:
      collectVariablesSet in interface RelNode
      Parameters:
      variableSet - receives variables known to be set by
    • childrenAccept

      public void childrenAccept(RelVisitor visitor)
      Description copied from interface: RelNode
      Interacts with the RelVisitor in a visitor pattern to traverse the tree of relational expressions.
      Specified by:
      childrenAccept in interface RelNode
      Parameters:
      visitor - Visitor that will traverse the tree of relational expressions
    • accept

      public RelNode accept(RelShuttle shuttle)
      Description copied from interface: RelNode
      Accepts a visit from a shuttle.
      Specified by:
      accept in interface RelNode
      Parameters:
      shuttle - Shuttle
      Returns:
      A copy of this node incorporating changes made by the shuttle to this node's children
    • accept

      public RelNode accept(RexShuttle shuttle)
      Description copied from interface: RelNode
      Accepts a visit from a shuttle. If the shuttle updates expression, then a copy of the relation should be created. This new relation might have a different row-type.
      Specified by:
      accept in interface RelNode
      Parameters:
      shuttle - Shuttle
      Returns:
      A copy of this node incorporating changes made by the shuttle to this node's children
    • computeSelfCost

      public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
      Description copied from interface: RelNode
      Returns the cost of this plan (not including children). The base implementation throws an error; derived classes should override.

      NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use RelMetadataQuery.getNonCumulativeCost(org.apache.calcite.rel.RelNode), which gives plugins a chance to override the rel's default ideas about cost.

      Specified by:
      computeSelfCost in interface RelNode
      Parameters:
      planner - Planner for cost calculation
      mq - Metadata query
      Returns:
      Cost of this plan (not including children)
    • metadata

      @Deprecated public final <@Nullable M extends @Nullable Metadata> M metadata(Class<@Nullable M> metadataClass, RelMetadataQuery mq)
      Deprecated.
      Description copied from interface: RelNode
      Returns a metadata interface.
      Specified by:
      metadata in interface RelNode
      Type Parameters:
      M - Type of metadata being requested
      Parameters:
      metadataClass - Metadata interface
      mq - Metadata query
      Returns:
      Metadata object that supplies the desired metadata (never null, although if the information is not present the metadata object may return null from all methods)
    • explain

      public void explain(RelWriter pw)
      Description copied from interface: RelNode
      Describes the inputs and attributes of this relational expression. Each node should call super.explain, then call the RelWriter.input(String, RelNode) and RelWriter.item(String, Object) methods for each input and attribute.
      Specified by:
      explain in interface RelNode
      Parameters:
      pw - Plan writer
    • explainTerms

      public RelWriter explainTerms(RelWriter pw)
      Describes the inputs and attributes of this relational expression. Each node should call super.explainTerms, then call the RelWriter.input(String, RelNode) and RelWriter.item(String, Object) methods for each input and attribute.
      Parameters:
      pw - Plan writer
      Returns:
      Plan writer for fluent-explain pattern
    • onRegister

      public RelNode onRegister(RelOptPlanner planner)
      Description copied from interface: RelNode
      Receives notification that this expression is about to be registered. The implementation of this method must at least register all child expressions.
      Specified by:
      onRegister in interface RelNode
      Parameters:
      planner - Planner that plans this relational node
      Returns:
      Relational expression that should be used by the planner
    • recomputeDigest

      public void recomputeDigest()
      Description copied from interface: RelNode
      Recomputes the digest.

      INTERNAL USE ONLY. For use by the planner.

      Specified by:
      recomputeDigest in interface RelNode
      See Also:
    • replaceInput

      public void replaceInput(int ordinalInParent, RelNode p)
      Description copied from interface: RelNode
      Replaces the ordinalInParentth input. You must override this method if you override RelNode.getInputs().
      Specified by:
      replaceInput in interface RelNode
      Parameters:
      ordinalInParent - Position of the child input, 0 is the first
      p - New node that should be put at position ordinalInParent
    • toString

      public String toString()
      Description; consists of id plus digest.
      Overrides:
      toString in class Object
    • getDescription

      @Deprecated public final String getDescription()
      Deprecated.
      Description copied from interface: RelOptNode
      Returns a string which describes the relational expression and, unlike RelOptNode.getDigest(), also includes the identity. Typically returns "rel#{id}:{digest}".
      Specified by:
      getDescription in interface RelOptNode
      Returns:
      String which describes the relational expression and, unlike RelOptNode.getDigest(), also includes the identity
    • getDigest

      public String getDigest()
      Description copied from interface: RelNode
      Returns a digest string of this RelNode.

      Each call creates a new digest string, so don't forget to cache the result if necessary.

      Specified by:
      getDigest in interface RelNode
      Specified by:
      getDigest in interface RelOptNode
      Returns:
      Digest string of this RelNode
      See Also:
    • getRelDigest

      public final RelDigest getRelDigest()
      Description copied from interface: RelNode
      Returns a digest of this RelNode.

      INTERNAL USE ONLY. For use by the planner.

      Specified by:
      getRelDigest in interface RelNode
      Returns:
      Digest of this RelNode
      See Also:
    • getTable

      public @Nullable RelOptTable getTable()
      Description copied from interface: RelNode
      If this relational expression represents an access to a table, returns that table, otherwise returns null.
      Specified by:
      getTable in interface RelNode
      Returns:
      If this relational expression represents an access to a table, returns that table, otherwise returns null
    • equals

      public final boolean equals(@Nullable Object obj)

      This method (and hashCode() is intentionally final. We do not want sub-classes of RelNode to redefine identity. Various algorithms (e.g. visitors, planner) can define the identity as meets their needs.

      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()

      This method (and equals(java.lang.Object) is intentionally final. We do not want sub-classes of RelNode to redefine identity. Various algorithms (e.g. visitors, planner) can define the identity as meets their needs.

      Overrides:
      hashCode in class Object
    • deepEquals

      @API(since="1.25", status=MAINTAINED) public boolean deepEquals(@Nullable Object obj)
      Equality check for RelNode digest.

      By default this method collects digest attributes from explainTerms(RelWriter), then compares each attribute pair. This should work well for most cases. If this method is a performance bottleneck for your project, or the default behavior can't handle your scenario properly, you can choose to override this method and deepHashCode(). See LogicalJoin as an example.

      Specified by:
      deepEquals in interface RelNode
      Returns:
      Whether the 2 RelNodes are equivalent or have the same digest.
      See Also:
    • deepHashCode

      @API(since="1.25", status=MAINTAINED) public int deepHashCode()
      Compute hash code for RelNode digest.
      Specified by:
      deepHashCode in interface RelNode
      See Also: