Class PivotNamespace
Object
gudusoft.gsqlparser.resolver2.namespace.AbstractNamespace
gudusoft.gsqlparser.resolver2.namespace.PivotNamespace
- All Implemented Interfaces:
INamespace
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDisplay name format for PIVOT tablestatic final StringDisplay name format for UNPIVOT tableFields inherited from class gudusoft.gsqlparser.resolver2.namespace.AbstractNamespace
columnSources, columnSourcesWithRefs, guessColumnStrategy, nameMatcher, node, referenceTraceabilityEnabled, validated -
Constructor Summary
ConstructorsConstructorDescriptionPivotNamespace(TTable pivotTable, TPivotClause pivotClause, TTable sourceTable, String alias, INameMatcher nameMatcher) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidSubclasses override this to perform actual validation logic.Get all column sources for this PIVOT namespace.Get all final physical tables this namespace depends on.Get a display name for this namespace (for debugging/error messages)Get the final physical table this namespace represents.Get the PIVOT clause.Get the set of pivot column names (from IN clause).Get the pivot table.Get the namespace representing the source table.Get the TTable that this namespace is associated with.Get the underlying table that PIVOT operates on.Check if a column exists in this namespace.booleanisPivotColumn(String columnName) Check if a column is a pivot column (from IN clause).booleanCheck if this is an UNPIVOT namespace.resolveColumn(String columnName) Resolve a column name to its source.voidsetSourceNamespace(INamespace sourceNamespace) Set the namespace representing the source table.toString()Methods inherited from class gudusoft.gsqlparser.resolver2.namespace.AbstractNamespace
addColumnSource, addColumnSource, enableReferenceTraceability, ensureValidated, getAllUniqueColumns, getColumnReferences, getColumnSourceWithReferences, getGuessColumnStrategy, getNameMatcher, getNode, isReferenceTraceabilityEnabled, isValidated, setGuessColumnStrategy, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface gudusoft.gsqlparser.resolver2.namespace.INamespace
addInferredColumn, getInferredColumns, getSelectStatement, getStarColumn, hasStarColumn, resolveColumnPath, supportsDynamicInference
-
Field Details
-
PIVOT_TABLE_SUFFIX
Display name format for PIVOT table- See Also:
-
UNPIVOT_TABLE_SUFFIX
Display name format for UNPIVOT table- See Also:
-
-
Constructor Details
-
PivotNamespace
public PivotNamespace(TTable pivotTable, TPivotClause pivotClause, TTable sourceTable, String alias, INameMatcher nameMatcher)
-
-
Method Details
-
isUnpivot
Check if this is an UNPIVOT namespace. -
setSourceNamespace
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
Check if a column is a pivot column (from IN clause). -
getDisplayName
Description copied from interface:INamespaceGet a display name for this namespace (for debugging/error messages) -
getFinalTable
Description copied from interface:INamespaceGet 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:INamespaceGet 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:
getAllFinalTablesin interfaceINamespace- Overrides:
getAllFinalTablesin classAbstractNamespace- Returns:
- List of all physical tables
-
doValidate
Description copied from class:AbstractNamespaceSubclasses override this to perform actual validation logic.- Specified by:
doValidatein classAbstractNamespace
-
hasColumn
Description copied from interface:INamespaceCheck if a column exists in this namespace. Returns a three-level answer: EXISTS, MAYBE, NOT_EXISTS- Specified by:
hasColumnin interfaceINamespace- Overrides:
hasColumnin classAbstractNamespace- Parameters:
columnName- Column name to check- Returns:
- Column existence level
-
resolveColumn
Description copied from interface:INamespaceResolve a column name to its source.- Specified by:
resolveColumnin interfaceINamespace- Overrides:
resolveColumnin classAbstractNamespace- 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:
getAllColumnSourcesin interfaceINamespace- Overrides:
getAllColumnSourcesin classAbstractNamespace- Returns:
- Map of column name -> ColumnSource
-
toString
- Overrides:
toStringin classAbstractNamespace
-