Package org.apache.calcite.rel
Class RelRoot
- java.lang.Object
-
- org.apache.calcite.rel.RelRoot
-
public class RelRoot extends java.lang.Object
Root of a tree ofRelNode
.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 thefields
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 asn
. You can represent this asRelRoot: { rel: Project(name, empno) TableScan(EMP) fields: [(0, "n"), (0, "n2"), (1, "n")] collation: [] }
-
-
Field Summary
Fields Modifier and Type Field Description RelCollation
collation
com.google.common.collect.ImmutableList<Pair<java.lang.Integer,java.lang.String>>
fields
SqlKind
kind
RelNode
rel
RelDataType
validatedRowType
-
Constructor Summary
Constructors Constructor Description RelRoot(RelNode rel, RelDataType validatedRowType, SqlKind kind, java.util.List<Pair<java.lang.Integer,java.lang.String>> fields, RelCollation collation)
Creates a RelRoot.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isCollationTrivial()
boolean
isNameTrivial()
boolean
isRefTrivial()
static RelRoot
of(RelNode rel, RelDataType rowType, SqlKind kind)
Creates a simple RelRoot.static RelRoot
of(RelNode rel, SqlKind kind)
Creates a simple RelRoot.RelNode
project()
Returns the root relational expression, creating aLogicalProject
if necessary to remove fields that are not needed.RelNode
project(boolean force)
Returns the root relational expression as aLogicalProject
.java.lang.String
toString()
RelRoot
withCollation(RelCollation collation)
RelRoot
withKind(SqlKind kind)
Creates a copy, assigning a new kind.RelRoot
withRel(RelNode rel)
Creates a copy of this RelRoot, assigning aRelNode
.
-
-
-
Field Detail
-
rel
public final RelNode rel
-
validatedRowType
public final RelDataType validatedRowType
-
kind
public final SqlKind kind
-
fields
public final com.google.common.collect.ImmutableList<Pair<java.lang.Integer,java.lang.String>> fields
-
collation
public final RelCollation collation
-
-
Constructor Detail
-
RelRoot
public RelRoot(RelNode rel, RelDataType validatedRowType, SqlKind kind, java.util.List<Pair<java.lang.Integer,java.lang.String>> fields, RelCollation collation)
Creates a RelRoot.- Parameters:
validatedRowType
- Original row type returned by query validatorkind
- Type of query (SELECT, UPDATE, ...)
-
-
Method Detail
-
of
public static RelRoot of(RelNode rel, RelDataType rowType, SqlKind kind)
Creates a simple RelRoot.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
withCollation
public RelRoot withCollation(RelCollation collation)
-
project
public RelNode project()
Returns the root relational expression, creating aLogicalProject
if necessary to remove fields that are not needed.
-
project
public RelNode project(boolean force)
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()
-
-