Class RelRoot


public class RelRoot extends Object
Root of a tree of RelNode.

One important reason that RelRoot exists is to deal with queries like


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 Details

  • Constructor Details

  • Method Details

    • of

      public static RelRoot of(RelNode rel, SqlKind kind)
      Creates a simple RelRoot.
    • of

      public static RelRoot of(RelNode rel, RelDataType rowType, SqlKind kind)
      Creates a simple RelRoot.
    • toString

      public String toString()
      toString in class Object
    • withRel

      public RelRoot withRel(RelNode rel)
      Creates a copy of this RelRoot, assigning a RelNode.
    • withKind

      public RelRoot withKind(SqlKind kind)
      Creates a copy, assigning a new kind.
    • withCollation

      public RelRoot withCollation(RelCollation collation)
    • withHints

      public RelRoot withHints(List<RelHint> hints)
      Creates a copy, assigning the query hints.
    • project

      public RelNode project()
      Returns the root relational expression, creating a LogicalProject if necessary to remove fields that are not needed.
    • project

      public RelNode project(boolean force)
      Returns the root relational expression as a LogicalProject.
      force - Create a Project even if all fields are used
    • isNameTrivial

      public boolean isNameTrivial()
    • isRefTrivial

      public boolean isRefTrivial()
    • isCollationTrivial

      public boolean isCollationTrivial()