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 DESC
Calcite 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 emp
The 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 Summary
FieldsModifier and TypeFieldDescriptionfinal RelCollation
final ImmutablePairList<Integer,
String> final com.google.common.collect.ImmutableList<RelHint>
final SqlKind
final RelNode
final RelDataType
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns true if the embedded relation has a single collation defined which matches the collation of this RelRoot, otherwise false.boolean
Returns true if the field names defined in this RelRoot are the same as the names of the embedded relation, otherwise false.boolean
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.static RelRoot
of
(RelNode rel, RelDataType rowType, SqlKind kind) Creates a simple RelRoot.static RelRoot
Creates a simple RelRoot.project()
Returns the root relational expression, creating aLogicalProject
if 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
-
RelRoot
public 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 validatorkind
- Type of query (SELECT, UPDATE, ...)
-
-
Method Details
-
of
Creates a simple RelRoot. -
of
Creates a simple RelRoot. -
toString
-
withRel
Creates a copy of this RelRoot, assigning aRelNode
. -
withKind
Creates a copy, assigning a new kind. -
withCollation
-
withHints
Creates a copy, assigning the query hints. -
project
Returns the root relational expression, creating aLogicalProject
if necessary to remove fields that are not needed. -
project
Returns the root relational expression as aLogicalProject
.- Parameters:
force
- Create a Project even if all fields are used
-
isNameTrivial
public 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
-
isRefTrivial
public 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
-
isCollationTrivial
public 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
-