Package org.apache.calcite.rel
Class RelRoot
java.lang.Object
org.apache.calcite.rel.RelRoot
Root of a tree of 
RelNode.
 One important reason that RelRoot exists is to deal with queries like
SELECT name
 FROM emp
 ORDER BY empno DESCCalcite knows that the result must be sorted, but cannot represent its
 sort order as a collation, because empno is not a field in the
 result.
 
Instead we represent this as
RelRoot: {
   rel: Sort($1 DESC)
          Project(name, empno)
            TableScan(EMP)
   fields: [0]
   collation: [1 DESC]
 }Note that the empno field is present in the result, but the
 fields mask tells the consumer to throw it away.
 
Another use case is queries like this:
SELECT name AS n, name AS n2, empno AS n
 FROM empThe there are multiple uses of the name field. and there are
 multiple columns aliased as n. You can represent this as
 
RelRoot: {
   rel: Project(name, empno)
          TableScan(EMP)
   fields: [(0, "n"), (0, "n2"), (1, "n")]
   collation: []
 }- 
Field SummaryFieldsModifier and TypeFieldDescriptionfinal RelCollationfinal ImmutablePairList<Integer,String> final com.google.common.collect.ImmutableList<RelHint>final SqlKindfinal RelNodefinal RelDataType
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleanReturns true if the embedded relation has a single collation defined which matches the collation of this RelRoot, otherwise false.booleanReturns true if the field names defined in this RelRoot are the same as the names of the embedded relation, otherwise false.booleanReturns true if the embedded relation is either a DML relation or if the field order defined in this RelRoot is the same as the field order of the embedded relation, otherwise false.static RelRootof(RelNode rel, RelDataType rowType, SqlKind kind) Creates a simple RelRoot.static RelRootCreates a simple RelRoot.project()Returns the root relational expression, creating aLogicalProjectif necessary to remove fields that are not needed.project(boolean force) Returns the root relational expression as aLogicalProject.toString()withCollation(RelCollation collation) Creates a copy, assigning the query hints.Creates a copy, assigning a new kind.Creates a copy of this RelRoot, assigning aRelNode.
- 
Field Details- 
rel
- 
validatedRowType
- 
kind
- 
fields
- 
collation
- 
hints
 
- 
- 
Constructor Details- 
RelRootpublic RelRoot(RelNode rel, RelDataType validatedRowType, SqlKind kind, Iterable<? extends Map.Entry<Integer, String>> fields, RelCollation collation, List<RelHint> hints) Creates a RelRoot.- Parameters:
- validatedRowType- Original row type returned by query validator
- kind- Type of query (SELECT, UPDATE, ...)
 
 
- 
- 
Method Details- 
ofCreates a simple RelRoot.
- 
ofCreates a simple RelRoot.
- 
toString
- 
withRelCreates a copy of this RelRoot, assigning aRelNode.
- 
withKindCreates a copy, assigning a new kind.
- 
withCollation
- 
withHintsCreates a copy, assigning the query hints.
- 
projectReturns the root relational expression, creating aLogicalProjectif necessary to remove fields that are not needed.
- 
projectReturns the root relational expression as aLogicalProject.- Parameters:
- force- Create a Project even if all fields are used
 
- 
isNameTrivialpublic boolean isNameTrivial()Returns true if the field names defined in this RelRoot are the same as the names of the embedded relation, otherwise false.Positive example (same names): RelRoot: { rel: Project(empno) TableScan(EMP) fields: [0 -> empno] collation: [] }Negative example (different names): RelRoot: { rel: Project(empno) TableScan(EMP) fields: [0 -> empid] collation: [] }- Returns:
- true if the field names are the same as in the embedded relation, otherwise false
 
- 
isRefTrivialpublic boolean isRefTrivial()Returns true if the embedded relation is either a DML relation or if the field order defined in this RelRoot is the same as the field order of the embedded relation, otherwise false.Positive example (same order): RelRoot: { rel: Project(name, empno) TableScan(EMP) fields: [0 -> name, 1 -> empno] collation: [] }Negative example (different order): RelRoot: { rel: Project(name, empno) TableScan(EMP) fields: [0 -> empno, 1 -> name] collation: [] }- Returns:
- true if the embedded relation is a DML relation or if the field names of the RelRoot are in the same order as in the embedded relation, otherwise false
 
- 
isCollationTrivialpublic boolean isCollationTrivial()Returns true if the embedded relation has a single collation defined which matches the collation of this RelRoot, otherwise false.- Returns:
- true if the embedded relation has a single collation which matches the collation of this RelRoot, otherwise false
 
 
-