Class AbstractRelNode

    • Field Detail

      • NEXT_ID

        private static final java.util.concurrent.atomic.AtomicInteger NEXT_ID
        Generator for id values.
      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • desc

        private java.lang.String desc
        Description, consists of id plus digest.
      • rowType

        protected RelDataType rowType
        Cached type of this relational expression.
      • id

        protected final int id
        unique id of this object -- for debugging
      • traitSet

        protected RelTraitSet traitSet
        The RelTraitSet that describes the traits of this RelNode.
    • Constructor Detail

    • Method Detail

      • copy

        public RelNode copy​(RelTraitSet traitSet,
                            java.util.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​(java.util.List<T> collection)
      • getChildExps

        public java.util.List<RexNode> getChildExps()
        Description copied from interface: RelNode
        Returns a list of this relational expression's child expressions. (These are scalar expressions, and so do not include the relational inputs that are returned by RelNode.getInputs().

        The caller should treat the list as unmodifiable; typical implementations will return an immutable list. If there are no child expressions, returns an empty list, not null.

        Specified by:
        getChildExps in interface RelNode
        Returns:
        List of this relational expression's child expressions
        See Also:
        RelNode.accept(org.apache.calcite.rex.RexShuttle)
      • 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

        public final Convention getConvention()
        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 java.lang.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
      • isDistinct

        public boolean isDistinct()
        Description copied from interface: RelNode
        Returns whether the same value will not come out twice. Default value is false, derived classes should override.
        Specified by:
        isDistinct in interface RelNode
        Returns:
        Whether the same value will not come out twice
      • isKey

        public boolean isKey​(ImmutableBitSet columns)
        Description copied from interface: RelNode
        Returns whether the result of this relational expression is uniquely identified by this columns with the given ordinals.

        For example, if this relational expression is a LogicalTableScan to T(A, B, C, D) whose key is (A, B), then isKey([0, 1]) yields true, and isKey([0]) and isKey([0, 2]) yields false.

        Specified by:
        isKey in interface RelNode
        Parameters:
        columns - Ordinals of key columns
        Returns:
        Whether the given columns are a key or a superset of a key
      • 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
      • getQuery

        public final RelOptQuery getQuery()
        Description copied from interface: RelNode
        Returns the sub-query this relational expression belongs to.
        Specified by:
        getQuery in interface RelNode
        Returns:
        Sub-query
      • 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 final java.lang.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,
                               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
      • isValid

        public boolean isValid​(boolean fail)
        Specified by:
        isValid in interface RelNode
      • getCollationList

        @Deprecated
        public java.util.List<RelCollation> getCollationList()
        Description copied from interface: RelNode
        Returns a description of the physical ordering (or orderings) of this relational expression. Never null.
        Specified by:
        getCollationList in interface RelNode
        Returns:
        Description of the physical ordering (or orderings) of this relational expression. Never null
      • 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 java.util.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
      • getRows

        public final double getRows()
        Specified by:
        getRows in interface RelNode
      • 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
      • getVariablesStopped

        public final java.util.Set<java.lang.String> getVariablesStopped()
        Description copied from interface: RelNode
        Returns the names of variables that are set in this relational expression but also used and therefore not available to parents of this relational expression.

        Note: only Correlate should set variables.

        Note: RelNode.getVariablesSet() is equivalent but returns CorrelationId rather than their names. It is preferable except for calling old methods that require a set of strings.

        Specified by:
        getVariablesStopped in interface RelNode
        Returns:
        Names of variables which are set in this relational expression
      • getVariablesSet

        public java.util.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.

        Note: only Correlate should set variables.

        Specified by:
        getVariablesSet in interface RelNode
        Returns:
        Names of variables which are set in this relational expression
      • collectVariablesUsed

        public void collectVariablesUsed​(java.util.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
      • collectVariablesSet

        public void collectVariablesSet​(java.util.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
      • metadata

        public final <M extends Metadata> M metadata​(java.lang.Class<M> metadataClass,
                                                     RelMetadataQuery mq)
        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)
      • 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 java.lang.String recomputeDigest()
        Description copied from interface: RelNode
        Computes the digest, assigns it, and returns it. For planner use only.
        Specified by:
        recomputeDigest in interface RelNode
        Returns:
        Digest of this relational expression
      • 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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getDescription

        public final java.lang.String getDescription()
        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 final java.lang.String getDigest()
        Description copied from interface: RelOptNode
        Returns a string which concisely describes the definition of this relational expression. Two relational expressions are equivalent if their digests and RelOptNode.getRowType() are the same.

        The digest does not contain the relational expression's identity -- that would prevent similar relational expressions from ever comparing equal -- but does include the identity of children (on the assumption that children have already been normalized).

        If you want a descriptive string which contains the identity, call Object.toString(), which always returns "rel#{id}:{digest}".

        Specified by:
        getDigest in interface RelOptNode
        Returns:
        Digest of this RelNode
      • getTable

        public 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
      • computeDigest

        protected java.lang.String computeDigest()
        Computes the digest. Does not modify this object.
        Returns:
        Digest
      • equals

        public final boolean equals​(java.lang.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 java.lang.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 java.lang.Object