public final class UsingScope extends Object
SELECT merged-key scope for JOIN ... USING.
Slice 64 admitted JOIN ... USING (k) at the predicate side
(joinColumnRefs). Slice 65 lifts the output / non-JOIN-ON
clause side: unqualified references to a USING merged key (in
SELECT / WHERE / GROUP BY / HAVING / ORDER BY) resolve to the merged
source list of every relation in the USING(k) equivalence class.
Equivalence classes are per-key (DSU over USING joins); multiple
disconnected classes can exist for the same key name. has(java.lang.String)
tells whether a name is a USING key; isAmbiguous(java.lang.String) signals
either disconnected-class ambiguity or an out-of-class same-named
column (caller throws with ambiguityReason(java.lang.String)).
Each SemanticIRBuilder.buildSelectStatementImpl invocation
resets its provider's using scope to EMPTY at entry, then
optionally narrows the provider with its own scope. This prevents an
enclosing SELECT's USING from leaking into recursive nested builds
(predicate-subquery bodies, scalar-subquery bodies, set-op branch
bodies, CTE bodies, FROM-subquery bodies).
| Modifier and Type | Class and Description |
|---|---|
static class |
UsingScope.EquivalenceClass
One equivalence class of FROM-clause relations connected by a
specific USING key.
|
static class |
UsingScope.MergedKeyEntry
One merged-key entry: a class and its FROM-ordered merged source
column refs (narrowed by catalog when available).
|
| Modifier and Type | Field and Description |
|---|---|
static UsingScope |
EMPTY |
| Constructor and Description |
|---|
UsingScope(Map<String,List<UsingScope.MergedKeyEntry>> entriesByName,
Map<String,String> ambiguityReasonByName) |
| Modifier and Type | Method and Description |
|---|---|
String |
ambiguityReason(String name)
Diagnostic text for an ambiguous name.
|
List<UsingScope.MergedKeyEntry> |
entriesFor(String name)
All entries for a USING key.
|
UsingScope.MergedKeyEntry |
entryContaining(String name,
TTable table)
Returns the
UsingScope.MergedKeyEntry whose equivalence class
contains table by object identity, or null if
table is not in any class for name. |
boolean |
has(String name)
True iff
name matches a USING key in this scope (case-insensitive). |
boolean |
isAmbiguous(String name)
True iff a bare unqualified
name reference is ambiguous —
either because two disconnected USING classes carry the same key
name, or because catalog declares the same column on a relation
outside the (single) equivalence class. |
boolean |
isEmpty()
Whether this scope has any merged-key entries.
|
List<ColumnRef> |
mergedSourcesFor(String name)
Flattened sources of the SINGLE entry for
name. |
public static final UsingScope EMPTY
public UsingScope(Map<String,List<UsingScope.MergedKeyEntry>> entriesByName, Map<String,String> ambiguityReasonByName)
public boolean has(String name)
name matches a USING key in this scope (case-insensitive).public boolean isAmbiguous(String name)
name reference is ambiguous —
either because two disconnected USING classes carry the same key
name, or because catalog declares the same column on a relation
outside the (single) equivalence class.public String ambiguityReason(String name)
null when not ambiguous.public List<UsingScope.MergedKeyEntry> entriesFor(String name)
!has(name).public UsingScope.MergedKeyEntry entryContaining(String name, TTable table)
UsingScope.MergedKeyEntry whose equivalence class
contains table by object identity, or null if
table is not in any class for name.
TTable instances do not override equals, so
identity check is the only safe membership test.
public List<ColumnRef> mergedSourcesFor(String name)
name.IllegalStateException - when the scope has zero or multiple
entries for name — callers must check
has(java.lang.String) and isAmbiguous(java.lang.String) first.public boolean isEmpty()