Class RelRoot

  • public class RelRoot
    extends java.lang.Object
    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 Detail

      • validatedRowType

        public final RelDataType validatedRowType
      • fields

        public final<Pair<java.lang.Integer,​java.lang.String>> fields
    • 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.
        validatedRowType - Original row type returned by query validator
        kind - Type of query (SELECT, UPDATE, ...)
    • Method Detail

      • toString

        public java.lang.String toString()
        toString in class java.lang.Object
      • withKind

        public RelRoot withKind​(SqlKind kind)
        Creates a copy, assigning a new kind.
      • 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()