Class AbstractRelNode
- java.lang.Object
-
- org.apache.calcite.rel.AbstractRelNode
-
- All Implemented Interfaces:
java.lang.Cloneable
,RelOptNode
,RelNode
- Direct Known Subclasses:
BiRel
,DruidQuery
,HepRelVertex
,MultiJoin
,RelSubset
,SetOp
,SingleRel
,TableFunctionScan
,TableScan
,Values
public abstract class AbstractRelNode extends java.lang.Object implements RelNode
Base class for every relational expression (RelNode
).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.calcite.rel.RelNode
RelNode.Context
-
-
Field Summary
Fields Modifier and Type Field Description private RelOptCluster
cluster
private java.lang.String
desc
Description, consists of id plus digest.protected java.lang.String
digest
A short description of this relational expression's type, inputs, and other properties.protected int
id
unique id of this object -- for debuggingprivate static org.slf4j.Logger
LOGGER
private static java.util.concurrent.atomic.AtomicInteger
NEXT_ID
Generator forid
values.protected RelDataType
rowType
Cached type of this relational expression.protected RelTraitSet
traitSet
The RelTraitSet that describes the traits of this RelNode.
-
Constructor Summary
Constructors Constructor Description AbstractRelNode(RelOptCluster cluster, RelTraitSet traitSet)
Creates anAbstractRelNode
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RelNode
accept(RelShuttle shuttle)
Accepts a visit from a shuttle.RelNode
accept(RexShuttle shuttle)
Accepts a visit from a shuttle.void
childrenAccept(RelVisitor visitor)
Interacts with theRelVisitor
in avisitor pattern
to traverse the tree of relational expressions.void
collectVariablesSet(java.util.Set<CorrelationId> variableSet)
Collects variables set by this expression.void
collectVariablesUsed(java.util.Set<CorrelationId> variableSet)
Collects variables known to be used by this expression or its descendants.protected java.lang.String
computeDigest()
Computes the digest.RelOptCost
computeSelfCost(RelOptPlanner planner)
RelOptCost
computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
Returns the cost of this plan (not including children).RelNode
copy(RelTraitSet traitSet, java.util.List<RelNode> inputs)
Creates a copy of this relational expression, perhaps changing traits and inputs.protected RelDataType
deriveRowType()
double
estimateRowCount(RelMetadataQuery mq)
Returns an estimate of the number of rows this relational expression will return.void
explain(RelWriter pw)
Describes the inputs and attributes of this relational expression.RelWriter
explainTerms(RelWriter pw)
Describes the inputs and attributes of this relational expression.java.util.List<RexNode>
getChildExps()
Returns a list of this relational expression's child expressions.RelOptCluster
getCluster()
Returns the cluster this relational expression belongs to.java.util.List<RelCollation>
getCollationList()
Deprecated.Convention
getConvention()
Return the CallingConvention trait from this RelNode'strait set
.java.lang.String
getCorrelVariable()
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.java.lang.String
getDescription()
Returns a string which describes the relational expression and, unlikeRelOptNode.getDigest()
, also includes the identity.java.lang.String
getDigest()
Returns a string which concisely describes the definition of this relational expression.RelDataType
getExpectedInputRowType(int ordinalInParent)
Returns the type of the rows expected for an input.int
getId()
Returns the ID of this relational expression, unique among all relational expressions created since the server was started.RelNode
getInput(int i)
Returns thei
th input relational expression.java.util.List<RelNode>
getInputs()
Returns an array of this relational expression's inputs.RelOptQuery
getQuery()
Returns the sub-query this relational expression belongs to.java.lang.String
getRelTypeName()
Returns the name of this relational expression's class, sans package name, for use in explain.double
getRows()
RelDataType
getRowType()
Returns the type of the rows returned by this relational expression.RelOptTable
getTable()
If this relational expression represents an access to a table, returns that table, otherwise returns null.RelTraitSet
getTraitSet()
Retrieves this RelNode's traits.java.util.Set<CorrelationId>
getVariablesSet()
Returns the variables that are set in this relational expression but also used and therefore not available to parents of this relational expression.java.util.Set<java.lang.String>
getVariablesStopped()
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.boolean
isDistinct()
Returns whether the same value will not come out twice.boolean
isKey(ImmutableBitSet columns)
Returns whether the result of this relational expression is uniquely identified by this columns with the given ordinals.boolean
isValid(boolean fail)
boolean
isValid(Litmus litmus, RelNode.Context context)
Returns whether this relational expression is valid.<M extends Metadata>
Mmetadata(java.lang.Class<M> metadataClass, RelMetadataQuery mq)
Returns a metadata interface.RelNode
onRegister(RelOptPlanner planner)
Receives notification that this expression is about to be registered.java.lang.String
recomputeDigest()
Computes the digest, assigns it, and returns it.void
register(RelOptPlanner planner)
Registers any special rules specific to this kind of relational expression.void
replaceInput(int ordinalInParent, RelNode p)
Replaces theordinalInParent
th input.protected static <T> T
sole(java.util.List<T> collection)
java.lang.String
toString()
-
-
-
Field Detail
-
NEXT_ID
private static final java.util.concurrent.atomic.AtomicInteger NEXT_ID
Generator forid
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.
-
digest
protected java.lang.String digest
A short description of this relational expression's type, inputs, and other properties. The string uniquely identifies the node; another node is equivalent if and only if it has the same value. Computed bycomputeDigest()
, assigned byonRegister(org.apache.calcite.plan.RelOptPlanner)
, returned bygetDigest()
.- See Also:
desc
-
cluster
private final RelOptCluster cluster
-
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
-
AbstractRelNode
public AbstractRelNode(RelOptCluster cluster, RelTraitSet traitSet)
Creates anAbstractRelNode
.
-
-
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.
-
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 byRelNode.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 interfaceRelNode
- 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 interfaceRelOptNode
- Returns:
- cluster
-
getConvention
public final Convention getConvention()
Description copied from interface:RelNode
Return the CallingConvention trait from this RelNode'strait set
.- Specified by:
getConvention
in interfaceRelNode
- 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 interfaceRelOptNode
- 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 interfaceRelNode
- 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 isfalse
, derived classes should override.- Specified by:
isDistinct
in interfaceRelNode
- 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.
-
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 interfaceRelOptNode
- Returns:
- Unique ID
-
getInput
public RelNode getInput(int i)
Description copied from interface:RelNode
Returns thei
th input relational expression.
-
getQuery
public final RelOptQuery getQuery()
Description copied from interface:RelNode
Returns the sub-query this relational expression belongs to.
-
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 callsuper.register
.
-
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 aorg.apache.calcite.rel.ArrayRel.ArrayReader
, this method returns "ArrayReader".- Specified by:
getRelTypeName
in interfaceRelNode
- 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.
-
getCollationList
@Deprecated public java.util.List<RelCollation> getCollationList()
Deprecated.Description copied from interface:RelNode
Returns a description of the physical ordering (or orderings) of this relational expression. Never null.- Specified by:
getCollationList
in interfaceRelNode
- Returns:
- Description of the physical ordering (or orderings) of this relational expression. Never null
-
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 interfaceRelNode
- Specified by:
getRowType
in interfaceRelOptNode
-
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 toRelNode.getRowType()
.- Specified by:
getExpectedInputRowType
in interfaceRelNode
- 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, notnull
.- Specified by:
getInputs
in interfaceRelNode
- Specified by:
getInputs
in interfaceRelOptNode
- 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 interfaceRelNode
- 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 returnsCorrelationId
rather than their names. It is preferable except for calling old methods that require a set of strings.- Specified by:
getVariablesStopped
in interfaceRelNode
- 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 interfaceRelNode
- 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 interfaceRelNode
- 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 interfaceRelNode
- Parameters:
variableSet
- receives variables known to be set by
-
childrenAccept
public void childrenAccept(RelVisitor visitor)
Description copied from interface:RelNode
Interacts with theRelVisitor
in avisitor pattern
to traverse the tree of relational expressions.- Specified by:
childrenAccept
in interfaceRelNode
- 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.
-
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.
-
computeSelfCost
public final RelOptCost computeSelfCost(RelOptPlanner planner)
- Specified by:
computeSelfCost
in interfaceRelNode
-
computeSelfCost
public 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 interfaceRelNode
- Parameters:
planner
- Planner for cost calculationmq
- Metadata query- Returns:
- Cost of this plan (not including 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 interfaceRelNode
- Type Parameters:
M
- Type of metadata being requested- Parameters:
metadataClass
- Metadata interfacemq
- 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 callsuper.explain
, then call theRelWriterImpl.input(String, RelNode)
andRelWriterImpl.item(String, Object)
methods for each input and attribute.
-
explainTerms
public RelWriter explainTerms(RelWriter pw)
Describes the inputs and attributes of this relational expression. Each node should callsuper.explainTerms
, then call theRelWriterImpl.input(String, RelNode)
andRelWriterImpl.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 interfaceRelNode
- 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 interfaceRelNode
- Returns:
- Digest of this relational expression
-
replaceInput
public void replaceInput(int ordinalInParent, RelNode p)
Description copied from interface:RelNode
Replaces theordinalInParent
th input. You must override this method if you overrideRelNode.getInputs()
.- Specified by:
replaceInput
in interfaceRelNode
- Parameters:
ordinalInParent
- Position of the child input, 0 is the firstp
- New node that should be put at positionordinalInParent
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getDescription
public final java.lang.String getDescription()
Description copied from interface:RelOptNode
Returns a string which describes the relational expression and, unlikeRelOptNode.getDigest()
, also includes the identity. Typically returns "rel#{id}:{digest}".- Specified by:
getDescription
in interfaceRelOptNode
- 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 and only if their digests 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 interfaceRelOptNode
- 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.
-
computeDigest
protected java.lang.String computeDigest()
Computes the digest. Does not modify this object.- Returns:
- Digest
-
-