public class UnnestNamespace extends AbstractNamespace
UNNEST(arr) AS x, the Trino family
CROSS JOIN UNNEST(arr) AS t(x), and the other dialects with an UNNEST relation.
UNNEST flattens an array into rows. For example:
- UNNEST(['a', 'b', 'c']) creates a virtual table with rows 'a', 'b', 'c'
- SELECT value FROM UNNEST(array_column) - 'value' is an implicit column name
The UNNEST namespace provides:
1. An implicit column for the unnested elements (named by alias or 'value')
2. Support for WITH OFFSET which adds an 'offset' column
3. Support for STRUCT arrays which expose struct field namescolumnSources, columnSourcesWithRefs, guessColumnStrategy, nameMatcher, node, referenceTraceabilityEnabled, validated| Constructor and Description |
|---|
UnnestNamespace(TTable unnestTable,
String alias) |
UnnestNamespace(TTable unnestTable,
String alias,
INameMatcher nameMatcher) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addInferredColumn(String columnName,
double confidence,
String evidence)
Add an inferred column to this namespace.
|
protected void |
doValidate()
Subclasses override this to perform actual validation logic.
|
List<TTable> |
getAllFinalTables()
Get all final physical tables this namespace depends on.
|
TExpression |
getArrayExpression()
Get the array expression being unnested.
|
String |
getDisplayName()
Get a display name for this namespace (for debugging/error messages)
|
TTable |
getFinalTable()
Get the final physical table this namespace represents.
|
String |
getImplicitColumnName()
Get the implicit column name for the unnested elements.
|
Set<String> |
getInferredColumns()
Get all columns that were inferred (not from SELECT list directly).
|
MetadataState |
getMetadataState()
Authoritative metadata state for this namespace (slice S4, plan §5.5).
|
String |
getOffsetColumnName()
Get the offset column name if WITH OFFSET is present.
|
TTable |
getSourceTable()
Get the TTable that this namespace is associated with.
|
TTable |
getUnnestTable() |
ColumnLevel |
hasColumn(String columnName)
Check if a column exists in this namespace.
|
boolean |
hasStarColumn()
Check if this namespace contains a star column (SELECT *).
|
boolean |
mayHoldUnknownFields()
FROM orders_raw, UNNEST(items): an unaliased value table whose element type is unknown exposes the
element's fields under their own names, so an unqualified name no table proves may be one of them (Mantis
4828, STRUCT tree plan rule R3). |
ColumnSource |
resolveColumn(String columnName)
Resolve a column name to its source.
|
ColumnSource |
resolveQualifiedStructField(String columnName)
Resolve a qualified struct field reference (e.g., "alias.field").
|
boolean |
supportsDynamicInference()
Check if this namespace supports dynamic column inference.
|
String |
toString() |
addColumnSource, addColumnSource, containsColumnByMatcher, containsColumnNameByMatcher, enableReferenceTraceability, ensureValidated, findColumnKeyByMatcher, getAllColumnSources, getAllUniqueColumns, getColumnReferences, getColumnSourceWithReferences, getGuessColumnStrategy, getNameMatcher, getNode, isReferenceTraceabilityEnabled, isValidated, noteColumnSourceAdded, setGuessColumnStrategy, validateclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetSelectStatement, getStarColumn, hasAuthoritativeOutputColumn, resolveColumnPathpublic UnnestNamespace(TTable unnestTable, String alias, INameMatcher nameMatcher)
public UnnestNamespace(TTable unnestTable, String alias)
public String getDisplayName()
INamespacepublic TTable getFinalTable()
INamespacepublic List<TTable> getAllFinalTables()
INamespacegetAllFinalTables in interface INamespacegetAllFinalTables in class AbstractNamespacepublic boolean mayHoldUnknownFields()
FROM orders_raw, UNNEST(items): an unaliased value table whose element type is unknown exposes the
element's fields under their own names, so an unqualified name no table proves may be one of them (Mantis
4828, STRUCT tree plan rule R3). BigQuery exposes the fields of a STRUCT element; Presto, Trino and Athena
expand an ARRAY(ROW) into one column per field, named after the field. Other vendors (PostgreSQL names the
one unnest column after the function) never expose fields this way.public MetadataState getMetadataState()
INamespaceUsed by the binding post-pass to gate UNKNOWN_COLUMN: the
post-pass only asserts a column is missing when the underlying namespace
declares MetadataState.FOUND. Namespaces that have not yet been
extended for binding return MetadataState.METADATA_UNAVAILABLE
by default — the safe answer.
nullprotected void doValidate()
AbstractNamespacedoValidate in class AbstractNamespacepublic boolean hasStarColumn()
INamespacepublic boolean supportsDynamicInference()
INamespacepublic boolean addInferredColumn(String columnName, double confidence, String evidence)
INamespacecolumnName - the column name to addconfidence - the confidence score (0.0 to 1.0)evidence - description of why this column was inferredpublic Set<String> getInferredColumns()
INamespacepublic 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 ColumnSource resolveQualifiedStructField(String columnName)
Use this method when resolving qualified column references like "x.field" where "x" is the UNNEST alias. This is appropriate for UNNEST of STRUCT arrays where the struct fields are accessed via the alias.
For unqualified column references, use resolveColumn(String) which
does NOT infer columns and returns null for unknown columns.
columnName - the column/field name (without the table qualifier)public TExpression getArrayExpression()
public String getImplicitColumnName()
public String getOffsetColumnName()
public TTable getUnnestTable()
public TTable getSourceTable()
public String toString()
toString in class AbstractNamespace