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 | 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<String> variableSet)
Collects variables set by this expression.
|
void |
collectVariablesUsed(Set<String> variableSet)
Collects variables known to be used by this expression or its
descendants.
|
RelOptCost |
computeSelfCost(RelOptPlanner planner)
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.
|
void |
explain(RelWriter pw)
Describes the inputs and attributes of this relational expression.
|
List<RexNode> |
getChildExps()
Deprecated.
use #accept(org.apache.calcite.rex.RexShuttle)
|
List<RelCollation> |
getCollationList()
Deprecated.
|
Convention |
getConvention()
Return the CallingConvention trait from this RelNode's
trait set. |
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.
|
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.
|
RelOptQuery |
getQuery()
Returns the sub-query this relational expression belongs to.
|
String |
getRelTypeName()
Returns the name of this relational expression's class, sans package
name, for use in explain.
|
double |
getRows()
Returns an estimate of the number of rows this relational expression will
return.
|
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.
|
Set<String> |
getVariablesStopped()
Returns the names of variables which 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)
Returns whether this relational expression is valid.
|
<M extends Metadata> |
metadata(Class<M> metadataClass)
Returns a metadata interface.
|
RelNode |
onRegister(RelOptPlanner planner)
Receives notification that this expression is about to be registered.
|
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 the
ordinalInParentth input. |
getCluster, getDescription, getDigest, getId, getTraitSet@Deprecated List<RexNode> getChildExps()
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.
accept(org.apache.calcite.rex.RexShuttle)Convention getConvention()
trait set.String getCorrelVariable()
boolean isDistinct()
false, derived classes should override.RelNode getInput(int i)
ith input relational expression.i - Ordinal of inputith inputRelOptQuery getQuery()
RelDataType 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 getRows()
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.
Set<String> getVariablesStopped()
Note: only Correlate should set
variables
void collectVariablesUsed(Set<String> variableSet)
variableSet - receives variables usedvoid collectVariablesSet(Set<String> 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
expressionsRelOptCost computeSelfCost(RelOptPlanner planner)
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 calculation<M extends Metadata> M metadata(Class<M> metadataClass)
M - Type of metadata being requestedmetadataClass - Metadata interfacevoid explain(RelWriter pw)
super.explain, then call the
RelWriterImpl.input(String, RelNode)
and
RelWriterImpl.item(String, Object)
methods for each input and attribute.pw - Plan writerRelNode onRegister(RelOptPlanner planner)
planner - Planner that plans this relational nodeString recomputeDigest()
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 ordinalInParentRelOptTable getTable()
String getRelTypeName()
org.apache.calcite.rel.ArrayRel.ArrayReader, this method returns
"ArrayReader".boolean isValid(boolean fail)
If assertions are enabled, this method is typically called with
fail = true, as follows:
This signals that the method can throw anassert rel.isValid(true)
AssertionError if it is
not valid.fail - Whether to fail if invalidAssertionError - if this relational expression is invalid and
fail=true and assertions are enabled@Deprecated List<RelCollation> getCollationList()
RelMetadataQuery.distribution(RelNode)RelNode 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
expressionsboolean isKey(ImmutableBitSet columns)
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.
columns - Ordinals of key columnsRelNode accept(RelShuttle shuttle)
shuttle - ShuttleRelNode accept(RexShuttle shuttle)
shuttle - ShuttleCopyright © 2012–2015 The Apache Software Foundation. All rights reserved.