Class SqlUnpivot

All Implemented Interfaces:
Cloneable

public class SqlUnpivot extends SqlCall
Parse tree node that represents UNPIVOT applied to a table reference (or sub-query).

Syntax:


 SELECT *
 FROM query
 UNPIVOT [ { INCLUDE | EXCLUDE } NULLS ] (
   columns FOR columns IN ( columns [ AS values ], ...))

 where:

 columns: column
        | '(' column, ... ')'
 values:  value
        | '(' value, ... ')'
 
  • Field Details

    • query

      public SqlNode query
    • includeNulls

      public final boolean includeNulls
    • measureList

      public final SqlNodeList measureList
    • axisList

      public final SqlNodeList axisList
    • inList

      public final SqlNodeList inList
  • Constructor Details

  • Method Details

    • getOperator

      public SqlOperator getOperator()
      Specified by:
      getOperator in class SqlCall
    • getOperandList

      public List<SqlNode> getOperandList()
      Description copied from class: SqlCall
      Returns the list of operands. The set and order of operands is call-specific.

      Note: the proper type would be List<@Nullable SqlNode>, however, it would trigger too many changes to the current codebase.

      Specified by:
      getOperandList in class SqlCall
      Returns:
      the list of call operands, never null, the operands can be null
    • setOperand

      public void setOperand(int i, @Nullable SqlNode operand)
      Description copied from class: SqlCall
      Changes the value of an operand. Allows some rewrite by SqlValidator; use sparingly.
      Overrides:
      setOperand in class SqlCall
      Parameters:
      i - Operand index
      operand - Operand value
    • unparse

      public void unparse(SqlWriter writer, int leftPrec, int rightPrec)
      Description copied from class: SqlNode
      Writes a SQL representation of this node to a writer.

      The leftPrec and rightPrec parameters give us enough context to decide whether we need to enclose the expression in parentheses. For example, we need parentheses around "2 + 3" if preceded by "5 *". This is because the precedence of the "*" operator is greater than the precedence of the "+" operator.

      The algorithm handles left- and right-associative operators by giving them slightly different left- and right-precedence.

      If SqlWriter.isAlwaysUseParentheses() is true, we use parentheses even when they are not required by the precedence rules.

      For the details of this algorithm, see SqlCall.unparse(org.apache.calcite.sql.SqlWriter, int, int).

      Overrides:
      unparse in class SqlCall
      Parameters:
      writer - Target writer
      leftPrec - The precedence of the SqlNode immediately preceding this node in a depth-first scan of the parse tree
      rightPrec - The precedence of the SqlNode immediately
    • forEachMeasure

      public void forEachMeasure(Consumer<SqlIdentifier> consumer)
      Returns the measure list as SqlIdentifiers.
    • forEachNameValues

      public void forEachNameValues(BiConsumer<SqlNodeList,@Nullable SqlNodeList> consumer)
      Returns contents of the IN clause (nodeList, valueList) pairs. valueList is null if the entry has no AS clause.
    • usedColumnNames

      public Set<String> usedColumnNames()
      Returns the set of columns that are referenced in the FOR clause. All columns that are not used will be part of the returned row.
    • aliasValue

      public static String aliasValue(SqlNodeList aliasList)
      Computes an alias. In the query fragment
      UNPIVOT ... FOR ... IN ((c1, c2) AS 'c1_c2', (c3, c4))
      note that (c3, c4) has no AS. The computed alias is 'C3_C4'.