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
Modifier and TypeFieldDescriptionfinal RelCollation
final ImmutablePairList<Integer,
String> final com.google.common.collect.ImmutableList<RelHint>
final SqlKind
final RelNode
final RelDataType
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
boolean
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() -
isRefTrivial
public boolean isRefTrivial() -
isCollationTrivial
public boolean isCollationTrivial()
-