Class SqlPivot

All Implemented Interfaces:

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


SELECT * FROM query PIVOT (agg, ... FOR axis, ... IN (in, ...)) AS alias
  • Field Details

  • 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
      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.
      setOperand in class SqlCall
      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).

      unparse in class SqlCall
      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
    • forEachAgg

      public void forEachAgg(BiConsumer<@Nullable String,SqlNode> consumer)
      Returns the aggregate list as (alias, call) pairs. If there is no 'AS', alias is null.
    • forEachNameValues

      public void forEachNameValues(BiConsumer<String,SqlNodeList> consumer)
      Returns the value list as (alias, node list) pairs.
    • usedColumnNames

      public Set<String> usedColumnNames()
      Returns the set of columns that are referenced as an argument to an aggregate function or in a column in the FOR clause. All columns that are not used will become "GROUP BY" columns.