public class RelRoot
extends java.lang.Object
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: []
}
Modifier and Type | Field and Description |
---|---|
RelCollation |
collation |
com.google.common.collect.ImmutableList<Pair<java.lang.Integer,java.lang.String>> |
fields |
SqlKind |
kind |
RelNode |
rel |
RelDataType |
validatedRowType |
Constructor and Description |
---|
RelRoot(RelNode rel,
RelDataType validatedRowType,
SqlKind kind,
java.util.List<Pair<java.lang.Integer,java.lang.String>> fields,
RelCollation collation)
Creates a RelRoot.
|
Modifier and Type | Method and 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 a
LogicalProject
if necessary to remove fields that are not needed. |
RelNode |
project(boolean force)
Returns the root relational expression as a
LogicalProject . |
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 a
RelNode . |
public final RelNode rel
public final RelDataType validatedRowType
public final SqlKind kind
public final com.google.common.collect.ImmutableList<Pair<java.lang.Integer,java.lang.String>> fields
public final RelCollation collation
public RelRoot(RelNode rel, RelDataType validatedRowType, SqlKind kind, java.util.List<Pair<java.lang.Integer,java.lang.String>> fields, RelCollation collation)
validatedRowType
- Original row type returned by query validatorkind
- Type of query (SELECT, UPDATE, ...)public static RelRoot of(RelNode rel, RelDataType rowType, SqlKind kind)
public java.lang.String toString()
toString
in class java.lang.Object
public RelRoot withCollation(RelCollation collation)
public RelNode project()
LogicalProject
if necessary to remove fields that are not needed.public RelNode project(boolean force)
LogicalProject
.force
- Create a Project even if all fields are usedpublic boolean isNameTrivial()
public boolean isRefTrivial()
public boolean isCollationTrivial()
Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.