public interface RelNode extends RelOptNode, Cloneable
RelNode is a relational expression.
Relational expressions process data, so their names are typically verbs: Sort, Join, Project, Filter, Scan, Sample.
A relational expression is not a scalar expression; see
SqlNode and RexNode.
If this type of relational expression has some particular planner rules,
it should implement the public static method
AbstractRelNode.register(org.apache.calcite.plan.RelOptPlanner).
When a relational expression comes to be implemented, the system allocates
a RelImplementor to manage the process. Every
implementable relational expression has a RelTraitSet describing its
physical attributes. The RelTraitSet always contains a Convention
describing how the expression passes data to its consuming
relational expression, but may contain other traits, including some applied
externally. Because traits can be applied externally, implementations of
RelNode should never assume the size or contents of their trait set (beyond
those traits configured by the RelNode itself).
For each calling-convention, there is a corresponding sub-interface of
RelNode. For example,
org.apache.calcite.adapter.enumerable.EnumerableRel
has operations to manage the conversion to a graph of
org.apache.calcite.adapter.enumerable.EnumerableConvention
calling-convention, and it interacts with a
EnumerableRelImplementor.
A relational expression is only required to implement its calling-convention's interface when it is actually implemented, that is, converted into a plan/program. This means that relational expressions which cannot be implemented, such as converters, are not required to implement their convention's interface.
Every relational expression must derive from AbstractRelNode. (Why
have the RelNode interface, then? We need a root interface,
because an interface can only derive from an interface.)
| Modifier and Type | Interface and Description |
|---|---|
static interface |
RelNode.Context
Context of a relational expression, for purposes of checking validity.
|
| Modifier and Type | Method and 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 the
RelVisitor in a
visitor pattern to
traverse the tree of relational expressions. |
void |
collectVariablesSet(Set<CorrelationId> variableSet)
Collects variables set by this expression.
|
void |
collectVariablesUsed(Set<CorrelationId> variableSet)
Collects variables known to be used by this expression or its
descendants.
|
@Nullable RelOptCost |
computeSelfCost(RelOptPlanner planner,
RelMetadataQuery mq)
Returns the cost of this plan (not including children).
|
RelNode |
copy(RelTraitSet traitSet,
List<RelNode> inputs)
Creates a copy of this relational expression, perhaps changing traits and
inputs.
|
boolean |
deepEquals(@Nullable Object obj)
Deep equality check for RelNode digest.
|
int |
deepHashCode()
Compute deep hash code for RelNode digest.
|
double |
estimateRowCount(RelMetadataQuery mq)
Returns an estimate of the number of rows this relational expression will
return.
|
default String |
explain()
Returns a relational expression string of this
RelNode. |
void |
explain(RelWriter pw)
Describes the inputs and attributes of this relational expression.
|
default boolean |
fieldIsNullable(int i)
Returns whether a field is nullable.
|
@Nullable Convention |
getConvention()
Return the CallingConvention trait from this RelNode's
trait set. |
@Nullable 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.
|
default String |
getDigest()
Returns a digest string of this
RelNode. |
RelDataType |
getExpectedInputRowType(int ordinalInParent)
Returns the type of the rows expected for an input.
|
RelNode |
getInput(int i)
Returns the
ith input relational expression. |
List<RelNode> |
getInputs()
Returns an array of this relational expression's inputs.
|
RelDigest |
getRelDigest()
Returns a digest of this
RelNode. |
String |
getRelTypeName()
Returns the name of this relational expression's class, sans package
name, for use in explain.
|
RelDataType |
getRowType()
Returns the type of the rows returned by this relational expression.
|
@Nullable RelOptTable |
getTable()
If this relational expression represents an access to a table, returns
that table, otherwise returns null.
|
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.
|
default boolean |
isEnforcer()
Indicates whether it is an enforcer operator, e.g.
|
boolean |
isValid(Litmus litmus,
@Nullable RelNode.Context context)
Returns whether this relational expression is valid.
|
<M extends Metadata> |
metadata(Class<M> metadataClass,
RelMetadataQuery mq)
Deprecated.
Use
RelMetadataQuery via RelOptNode.getCluster(). |
RelNode |
onRegister(RelOptPlanner planner)
Receives notification that this expression is about to be registered.
|
void |
recomputeDigest()
Recomputes the digest.
|
void |
register(RelOptPlanner planner)
Registers any special rules specific to this kind of relational
expression.
|
void |
replaceInput(int ordinalInParent,
RelNode p)
Replaces the
ordinalInParentth input. |
getCluster, getDescription, getId, getTraitSet@Pure @Nullable Convention getConvention()
trait set.@Nullable String getCorrelVariable()
RelNode getInput(int i)
ith input relational expression.i - Ordinal of inputith inputRelDataType getRowType()
getRowType in interface RelOptNodeRelDataType getExpectedInputRowType(int ordinalInParent)
getRowType().ordinalInParent - input's 0-based ordinal with respect to this
parent relList<RelNode> getInputs()
null.getInputs in interface RelOptNodedouble estimateRowCount(RelMetadataQuery mq)
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.
mq - Metadata querySet<CorrelationId> getVariablesSet()
Note: only Correlate should set
variables.
void collectVariablesUsed(Set<CorrelationId> variableSet)
variableSet - receives variables usedvoid collectVariablesSet(Set<CorrelationId> variableSet)
variableSet - receives variables known to be set byvoid childrenAccept(RelVisitor visitor)
RelVisitor in a
visitor pattern to
traverse the tree of relational expressions.visitor - Visitor that will traverse the tree of relational
expressions@Nullable RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
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.
planner - Planner for cost calculationmq - Metadata query@Deprecated <M extends Metadata> M metadata(Class<M> metadataClass, RelMetadataQuery mq)
RelMetadataQuery via RelOptNode.getCluster().M - Type of metadata being requestedmetadataClass - Metadata interfacemq - Metadata queryvoid explain(RelWriter pw)
super.explain, then call the
RelWriter.input(String, RelNode)
and
RelWriter.item(String, Object)
methods for each input and attribute.pw - Plan writerdefault String explain()
RelNode.
The string returned is the same as
RelOptUtil.toString(org.apache.calcite.rel.RelNode).
This method is intended mainly for use while debugging in an IDE,
as a convenient short-hand for RelOptUtil.toString.
We recommend that classes implementing this interface
do not override this method.RelNodeRelNode onRegister(RelOptPlanner planner)
planner - Planner that plans this relational nodedefault String getDigest()
RelNode.
Each call creates a new digest string, so don't forget to cache the result if necessary.
getDigest in interface RelOptNodeRelNodegetRelDigest()@API(since="1.24",
status=INTERNAL)
RelDigest getRelDigest()
RelNode.
INTERNAL USE ONLY. For use by the planner.
RelNodegetDigest()@API(since="1.24",
status=INTERNAL)
void recomputeDigest()
INTERNAL USE ONLY. For use by the planner.
getDigest()@EnsuresNonNullIf(expression="#1",
result=true)
boolean deepEquals(@Nullable Object obj)
By default this method collects digest attributes from explain terms, then compares each attribute pair.
deepHashCode()int deepHashCode()
deepEquals(Object)void replaceInput(int ordinalInParent,
RelNode p)
ordinalInParentth input. You must
override this method if you override getInputs().ordinalInParent - Position of the child input, 0 is the firstp - New node that should be put at position ordinalInParent@Nullable RelOptTable getTable()
String getRelTypeName()
org.apache.calcite.rel.ArrayRel.ArrayReader, this method returns
"ArrayReader".boolean isValid(Litmus litmus, @Nullable RelNode.Context context)
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.
litmus - What to do if invalidcontext - Context for validity checkingAssertionError - if this relational expression is invalid and
litmus is THROWRelNode copy(RelTraitSet traitSet, List<RelNode> inputs)
Sub-classes with other important attributes are encouraged to create variants of this method with more parameters.
traitSet - Trait setinputs - Inputsvoid register(RelOptPlanner planner)
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.
planner - Planner to be used to register additional relational
expressionsdefault boolean isEnforcer()
RelNode accept(RelShuttle shuttle)
shuttle - ShuttleRelNode accept(RexShuttle shuttle)
shuttle - Shuttledefault boolean fieldIsNullable(int i)
Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.