public final class Resolver2NameBindingProvider extends Object implements NameBindingProvider
NameBindingProvider backed by the data already attached to AST
nodes by TSQLResolver2 during TGSqlParser.parse().
Slice 1/2 only handled RelationKind.TABLE. Slice 3 adds
RelationKind.CTE via withCteContext(Set): when the
provider is given a non-empty CTE-name set, a FROM-clause reference
whose name (case-insensitive) is in the set binds as
RelationKind.CTE instead of RelationKind.TABLE.
| Constructor and Description |
|---|
Resolver2NameBindingProvider() |
Resolver2NameBindingProvider(TSQLEnv sqlEnv)
Slice 58 — construct a provider with catalog access.
|
| Modifier and Type | Method and Description |
|---|---|
ColumnBinding |
bindColumn(TObjectName columnRef)
Resolve a column-typed
TObjectName to a ColumnBinding. |
RelationBinding |
bindRelation(TTable table)
Resolve a FROM-clause relation reference to a
RelationBinding. |
Map<String,List<String>> |
getInScopeRelationColumns()
Slice 60 — return the in-scope relation column map last set via
NameBindingProvider.withInScopeRelationColumns(java.util.Map<java.lang.String, java.util.List<java.lang.String>>). |
List<String> |
getRelationColumnNames(TTable table)
Slice 58 — catalog-known column names for
table in catalog
declaration order, or null when no catalog information is
available for this relation. |
UsingScope |
getUsingScope()
Slice 65 — return the using scope last set via
NameBindingProvider.withUsingScope(gudusoft.gsqlparser.ir.semantic.binding.UsingScope). |
boolean |
isCalculatedProjectionAliasFallback(TObjectName columnRef,
TSelectSqlStatement enclosingSelect)
Slice 19: detect alias-bound PARTITION BY / OVER ORDER BY refs.
|
NameBindingProvider |
withCteContext(Set<String> cteNamesInScope)
Return a new provider configured for a CTE scope.
|
NameBindingProvider |
withInScopeRelationColumns(Map<String,List<String>> nameToColumns)
Slice 60 — return a new provider scoped with a map of "in-scope
relation alias → published column names" for the current
consuming SELECT.
|
NameBindingProvider |
withSourceTableFallback(boolean enabled)
Slice 93 — return a new provider that trusts Phase 1's
linkColumnToTable-set TObjectName.getSourceTable()
as an EXACT_MATCH when Phase 2 (TSQLResolver2) left
TObjectName.getResolution() null. |
NameBindingProvider |
withTolerantOuterBinding(Set<String> innerLocalAliasesLower)
Slice 117 — return a new provider that admits qualified outer-scope
column references as synthetic EXACT_MATCH bindings instead of
letting them surface as
NOT_FOUND. |
NameBindingProvider |
withUsingScope(UsingScope scope)
Slice 65 — return a new provider scoped with the
UsingScope
for the current SELECT body. |
public Resolver2NameBindingProvider()
public Resolver2NameBindingProvider(TSQLEnv sqlEnv)
sqlEnv is used only by getRelationColumnNames(TTable) for
star expansion; the resolver binding paths remain unchanged.public NameBindingProvider withCteContext(Set<String> cteNamesInScope)
NameBindingProviderThe set is treated as case-insensitive by convention; callers should pass already-lowercased CTE names.
withCteContext in interface NameBindingProviderpublic NameBindingProvider withInScopeRelationColumns(Map<String,List<String>> nameToColumns)
NameBindingProviderSemanticIRBuilder.tryExpandStar
to expand SELECT * / SELECT alias.* when the
FROM-clause relation binds to a CTE or a FROM-subquery body
already built earlier in the same build() invocation.
Semantics are REPLACE, not merge: callers always pass the complete visible map for the scope. Implementations must defensively copy and lower-case keys; values should be made unmodifiable. The default returns the same instance (no-op).
NameBindingProvider.withCteContext(Set) and
withInScopeRelationColumns are independent facets of the
same per-scope provider context. Implementations must preserve
the other facet's state across each narrower call.
withInScopeRelationColumns in interface NameBindingProviderpublic NameBindingProvider withUsingScope(UsingScope scope)
NameBindingProviderUsingScope
for the current SELECT body. Used by collectors and
SemanticIRBuilder.expandBareStarOverUsing to resolve
unqualified merged-key references to the merged source list.
Semantics are REPLACE, not merge: each
buildSelectStatementImpl invocation MUST call this with
UsingScope.EMPTY at entry so an enclosing SELECT's USING
cannot leak into recursive nested builds (predicate-subquery
bodies, scalar-subquery bodies, set-op branch bodies, CTE bodies,
FROM-subquery bodies all see only their own scope).
NameBindingProvider.withCteContext(java.util.Set),
NameBindingProvider.withInScopeRelationColumns(java.util.Map), and
withUsingScope are independent facets of the same
per-scope provider context. Implementations must preserve the
other facets' state across each narrower call.
Default returns the same instance (no-op).
withUsingScope in interface NameBindingProviderpublic NameBindingProvider withSourceTableFallback(boolean enabled)
NameBindingProviderlinkColumnToTable-set TObjectName.getSourceTable()
as an EXACT_MATCH when Phase 2 (TSQLResolver2) left
TObjectName.getResolution() null. Used for Hive multi-insert
sub-SELECT bodies whose secondary branches are not traversed by
Resolver2 during TGSqlParser.parse(); without the fallback,
those branches would universally fail with NOT_FOUND.
Safety: the fallback fires only when resolution == null
(proves Phase 2 did not run, NOT that it explicitly rejected) AND
the column's SQL-written qualifier (if any) is consistent with
Phase 1's chosen source table — the implementation verifies the
qualifier matches the source's name or alias case-insensitively
before promoting.
Default returns the same instance (no-op).
withSourceTableFallback in interface NameBindingProviderpublic NameBindingProvider withTolerantOuterBinding(Set<String> innerLocalAliasesLower)
NameBindingProviderNOT_FOUND. Used by the UPDATE
SET-RHS scalar-subquery extractor so a correlated outer reference
like t.k (where t is the UPDATE target or a
FROM-side outer relation, NOT inside the inner SELECT's FROM list)
survives appendMergedOrBoundColumnRef's strict
non-EXACT_MATCH reject. The slice-11
promoteCorrelatedRefsToOuterReference then sees the ref's
alias and synthesises an OUTER_REFERENCE relation.
The innerLocalAliasesLower argument scopes the fallback:
a qualified ref whose qualifier IS in the inner local aliases is
NOT promoted (typos like t.bad_col where t is the
inner FROM alias still reject with COLUMN_BINDING_NON_EXACT
— they are real errors). Unqualified refs are NOT promoted (their
binding remains ambiguous between inner and outer).
Passing an empty or null set disables the fallback (no-op).
Default returns the same instance (no-op).
withTolerantOuterBinding in interface NameBindingProviderpublic UsingScope getUsingScope()
NameBindingProviderNameBindingProvider.withUsingScope(gudusoft.gsqlparser.ir.semantic.binding.UsingScope). Default returns UsingScope.EMPTY.getUsingScope in interface NameBindingProviderpublic Map<String,List<String>> getInScopeRelationColumns()
NameBindingProviderNameBindingProvider.withInScopeRelationColumns(java.util.Map<java.lang.String, java.util.List<java.lang.String>>). Default returns an empty
map.getInScopeRelationColumns in interface NameBindingProviderpublic List<String> getRelationColumnNames(TTable table)
NameBindingProvidertable in catalog
declaration order, or null when no catalog information is
available for this relation.
Used by SemanticIRBuilder.tryExpandStar to expand
SELECT * and SELECT alias.* projections into per-
column OutputColumns, each
carrying a ColumnRef to the
underlying base column.
Default returns null so providers without catalog access
fall through transparently and the builder emits a structured
unsupported diagnostic. Resolver2NameBindingProvider
overrides this when constructed with a non-null TSQLEnv.
Implementations must not return an empty list to mean
"catalog known but no columns"; an empty list is treated
identically to null (no usable catalog) by the builder.
getRelationColumnNames in interface NameBindingProvidertable - the FROM-clause relation node being expanded; never
null in practice (the builder filters out null tables
before calling)public RelationBinding bindRelation(TTable table)
NameBindingProviderRelationBinding.
Returns null when the binding is not available (e.g. unresolved).bindRelation in interface NameBindingProviderpublic ColumnBinding bindColumn(TObjectName columnRef)
NameBindingProviderTObjectName to a ColumnBinding.
Returns null when the binding is not available; callers must
then decide whether to treat that as a hard error.bindColumn in interface NameBindingProviderpublic boolean isCalculatedProjectionAliasFallback(TObjectName columnRef, TSelectSqlStatement enclosingSelect)
The check fires only when ALL of:
columnRef is unqualified (getTableToken() == null);
a qualified ref like e.doubled explicitly names a FROM
relation, not a SELECT alias.!hasDefiniteEvidence()); the discriminator only
fires for the heuristic inferred_from_usage fallback
in TableNamespace.resolveColumn.enclosingSelect's result-column
list exposes the same name (case-insensitive) AND its
expression is a calculated expression (anything but a simple
column reference / star).If multiple result columns share the exposed name and at least
one is calculated, the method returns true — order-
independent rejection keeps the slice invariant deterministic.
Classification reuses ColumnSource.isCalculatedColumn()
by constructing a transient ColumnSource pinned to the
candidate TResultColumn; the helper inspects only the
definition-node expression and is independent of namespace state.
isCalculatedProjectionAliasFallback in interface NameBindingProvidercolumnRef - the column-typed AST node being inspectedenclosingSelect - the SELECT statement whose result columns
define the alias scope; the builder already
holds this and passes it in (avoids
context-dependent walks inside the resolver
layer)