Class PivotNamespace

Object
gudusoft.gsqlparser.resolver2.namespace.AbstractNamespace
gudusoft.gsqlparser.resolver2.namespace.PivotNamespace
All Implemented Interfaces:
INamespace

public class PivotNamespace extends AbstractNamespace
Namespace representing a PIVOT table.

A PIVOT transforms rows into columns using an aggregate function:

 SELECT ...
 FROM source_table
 PIVOT (aggregate_function(value_column) FOR pivot_column IN (val1, val2, ...)) AS alias
 

The PIVOT produces:

  • Columns from the IN clause (val1, val2, ...) - these are the pivoted columns
  • Pass-through columns from the source table (all columns NOT used in aggregate or FOR clause)

For column resolution purposes:

  • Pivot columns (from IN clause) resolve to the PivotNamespace
  • Other columns may come from the source table (pass-through columns)
  • Field Details

  • Constructor Details

  • Method Details

    • isUnpivot

      public boolean isUnpivot()
      Check if this is an UNPIVOT namespace.
    • setSourceNamespace

      public void setSourceNamespace(INamespace sourceNamespace)
      Set the namespace representing the source table. This is used for resolving pass-through columns.
    • getSourceNamespace

      Get the namespace representing the source table.
    • getPivotTable

      Get the pivot table.
    • getUnderlyingSourceTable

      Get the underlying table that PIVOT operates on. This is the table whose columns are being pivoted.
    • getSourceTable

      Get the TTable that this namespace is associated with. Used for legacy sync to set TObjectName.sourceTable. For TableNamespace: returns the table itself For SubqueryNamespace: returns the TTable wrapping the subquery For CTENamespace: returns the CTE referencing table For others: returns null For PivotNamespace, returns the PIVOT table (the result of the PIVOT operation). This is the immediate source table for columns resolved through this PIVOT.
      Returns:
      The source TTable, or null if not applicable
    • getPivotClause

      Get the PIVOT clause.
    • getPivotColumns

      Get the set of pivot column names (from IN clause).
    • isPivotColumn

      public boolean isPivotColumn(String columnName)
      Check if a column is a pivot column (from IN clause).
    • getDisplayName

      Description copied from interface: INamespace
      Get a display name for this namespace (for debugging/error messages)
    • getFinalTable

      Description copied from interface: INamespace
      Get the final physical table this namespace represents. For tables: returns the table itself For subqueries/CTEs: recursively traces back to physical table(s)
      Returns:
      Physical table, or null if not determinable
    • getAllFinalTables

      Description copied from interface: INamespace
      Get all final physical tables this namespace depends on. For simple table namespace: returns single table For subquery/CTE: returns all tables in the query tree
      Specified by:
      getAllFinalTables in interface INamespace
      Overrides:
      getAllFinalTables in class AbstractNamespace
      Returns:
      List of all physical tables
    • doValidate

      protected void doValidate()
      Description copied from class: AbstractNamespace
      Subclasses override this to perform actual validation logic.
      Specified by:
      doValidate in class AbstractNamespace
    • hasColumn

      public ColumnLevel hasColumn(String columnName)
      Description copied from interface: INamespace
      Check if a column exists in this namespace. Returns a three-level answer: EXISTS, MAYBE, NOT_EXISTS
      Specified by:
      hasColumn in interface INamespace
      Overrides:
      hasColumn in class AbstractNamespace
      Parameters:
      columnName - Column name to check
      Returns:
      Column existence level
    • resolveColumn

      public ColumnSource resolveColumn(String columnName)
      Description copied from interface: INamespace
      Resolve a column name to its source.
      Specified by:
      resolveColumn in interface INamespace
      Overrides:
      resolveColumn in class AbstractNamespace
      Parameters:
      columnName - Column name to resolve
      Returns:
      ColumnSource if found, null otherwise
    • getAllColumnSources

      Get all column sources for this PIVOT namespace. This includes both pivot columns (from IN clause) and pass-through columns from the source.

      For PIVOT, the output columns are:

      • Pivot columns: generated from IN clause values (e.g., 'AA', 'KH', 'DL', '9E')
      • Pass-through columns: source columns NOT consumed by FOR or aggregate

      This method is critical for star column expansion: when outer query uses SELECT * from a PIVOT table, we need to return ALL columns the pivot table exposes.

      Specified by:
      getAllColumnSources in interface INamespace
      Overrides:
      getAllColumnSources in class AbstractNamespace
      Returns:
      Map of column name -> ColumnSource
    • toString

      public String toString()
      Overrides:
      toString in class AbstractNamespace