public class PivotNamespace extends AbstractNamespace
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:
For column resolution purposes:
| Modifier and Type | Field and Description |
|---|---|
static String |
PIVOT_TABLE_SUFFIX
Display name format for PIVOT table
|
static String |
UNPIVOT_TABLE_SUFFIX
Display name format for UNPIVOT table
|
columnSources, columnSourcesWithRefs, guessColumnStrategy, nameMatcher, node, referenceTraceabilityEnabled, validated| Constructor and Description |
|---|
PivotNamespace(TTable pivotTable,
TPivotClause pivotClause,
TTable sourceTable,
String alias,
INameMatcher nameMatcher) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doValidate()
Subclasses override this to perform actual validation logic.
|
Map<String,ColumnSource> |
getAllColumnSources()
Get all column sources for this PIVOT namespace.
|
List<TTable> |
getAllFinalTables()
Get all final physical tables this namespace depends on.
|
String |
getDisplayName()
Get a display name for this namespace (for debugging/error messages)
|
TTable |
getFinalTable()
Get the final physical table this namespace represents.
|
TPivotClause |
getPivotClause()
Get the PIVOT clause.
|
Set<String> |
getPivotColumns()
Get the set of pivot column names (from IN clause).
|
TTable |
getPivotTable()
Get the pivot table.
|
INamespace |
getSourceNamespace()
Get the namespace representing the source table.
|
TTable |
getSourceTable()
Get the TTable that this namespace is associated with.
|
TTable |
getUnderlyingSourceTable()
Get the underlying table that PIVOT operates on.
|
ColumnLevel |
hasColumn(String columnName)
Check if a column exists in this namespace.
|
boolean |
isPivotColumn(String columnName)
Check if a column is a pivot column (from IN clause).
|
boolean |
isUnpivot()
Check if this is an UNPIVOT namespace.
|
ColumnSource |
resolveColumn(String columnName)
Resolve a column name to its source.
|
void |
setSourceNamespace(INamespace sourceNamespace)
Set the namespace representing the source table.
|
String |
toString() |
addColumnSource, addColumnSource, enableReferenceTraceability, ensureValidated, getAllUniqueColumns, getColumnReferences, getColumnSourceWithReferences, getGuessColumnStrategy, getNameMatcher, getNode, isReferenceTraceabilityEnabled, isValidated, setGuessColumnStrategy, validateclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddInferredColumn, getInferredColumns, getSelectStatement, getStarColumn, hasStarColumn, resolveColumnPath, supportsDynamicInferencepublic static final String PIVOT_TABLE_SUFFIX
public static final String UNPIVOT_TABLE_SUFFIX
public PivotNamespace(TTable pivotTable, TPivotClause pivotClause, TTable sourceTable, String alias, INameMatcher nameMatcher)
public boolean isUnpivot()
public void setSourceNamespace(INamespace sourceNamespace)
public INamespace getSourceNamespace()
public TTable getPivotTable()
public TTable getUnderlyingSourceTable()
public TTable getSourceTable()
public TPivotClause getPivotClause()
public Set<String> getPivotColumns()
public boolean isPivotColumn(String columnName)
public String getDisplayName()
INamespacepublic TTable getFinalTable()
INamespacepublic List<TTable> getAllFinalTables()
INamespacegetAllFinalTables in interface INamespacegetAllFinalTables in class AbstractNamespaceprotected void doValidate()
AbstractNamespacedoValidate in class AbstractNamespacepublic ColumnLevel hasColumn(String columnName)
INamespacehasColumn in interface INamespacehasColumn in class AbstractNamespacecolumnName - Column name to checkpublic ColumnSource resolveColumn(String columnName)
INamespaceresolveColumn in interface INamespaceresolveColumn in class AbstractNamespacecolumnName - Column name to resolvepublic Map<String,ColumnSource> getAllColumnSources()
For PIVOT, the output columns are:
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.
getAllColumnSources in interface INamespacegetAllColumnSources in class AbstractNamespacepublic String toString()
toString in class AbstractNamespace