public class FromScopeIndex extends Object
This class optimizes O(N) linear scans to O(1) hash lookups for common operations like finding tables by alias/name and finding candidate namespaces for star column inference.
The index is built lazily on first access and cached for subsequent lookups. This avoids the overhead of building the index when it's not needed.
Performance improvement: For queries with N tables and M column references, reduces complexity from O(N*M) to O(N + M).
Slice S2 — vendor-aware identifier compares. Pre-S2 keys were
built via raw String.toLowerCase() which broke quoted-sensitive
dialects (Oracle / Postgres / Snowflake / Hive / Teradata quoted) and
BigQuery's case-sensitive table rule. S2 stores aliases / display names
raw (preserving quotes and original case) and routes lookups
through IdentifierService via the supplied INameMatcher
with ESQLDataObjectType.dotTable. The exact-text fast probe
still handles same-as-written queries in O(1); cross-case / quoted-vs-
unquoted lookups fall through to a vendor-aware linear scan. Storing
the raw form is critical: a normalized key would lose quote provenance
— codex round-1 review caught that comparing the stripped-and-folded
stored key against the raw input would false-positive an unquoted
probe against a quoted alias on strict-case dialects.
| Constructor and Description |
|---|
FromScopeIndex(List<ScopeChild> children)
Creates an index from the given list of scope children using a
vendor-agnostic
DefaultNameMatcher. |
FromScopeIndex(List<ScopeChild> children,
INameMatcher nameMatcher)
Creates an index from the given list of scope children, using the
supplied matcher to normalize alias / table-name keys per-vendor.
|
| Modifier and Type | Method and Description |
|---|---|
ScopeChild |
findByAlias(String alias)
Finds a ScopeChild by its alias (vendor-aware).
|
ScopeChild |
findByQualifier(String qualifier)
Finds a ScopeChild by alias first, then by namespace name (vendor-aware).
|
INamespace |
findCandidateNamespace(String tablePrefix)
Finds a candidate namespace for column resolution.
|
TTable |
findTableByQualifier(String qualifier)
Gets the TTable from a ScopeChild by qualifier, if the namespace represents a table.
|
static FromScopeIndex |
fromScope(IScope scope)
Creates an index from a scope, extracting the FromScope if needed.
|
int |
getChildCount()
Gets the total number of children indexed.
|
INamespace |
getPreferredStarNamespace()
Gets the first namespace that supports star columns or dynamic inference.
|
boolean |
isEmpty()
Checks if the index is empty.
|
String |
toString() |
public FromScopeIndex(List<ScopeChild> children)
DefaultNameMatcher. Prefer the matcher-aware
constructor; this overload exists for synthetic / unit-test scopes
that have no GlobalScope above them.children - The list of ScopeChild from a FromScopepublic FromScopeIndex(List<ScopeChild> children, INameMatcher nameMatcher)
children - The list of ScopeChild from a FromScopenameMatcher - Vendor-aware matcher (typically the GlobalScope's)public ScopeChild findByAlias(String alias)
alias - The alias to search forpublic ScopeChild findByQualifier(String qualifier)
qualifier - The qualifier (alias or table name) to search forpublic TTable findTableByQualifier(String qualifier)
qualifier - The qualifier (alias or table name) to search forpublic INamespace getPreferredStarNamespace()
public INamespace findCandidateNamespace(String tablePrefix)
If a table prefix is provided, looks up by that prefix. Otherwise, returns the first star/dynamic namespace for unqualified columns.
tablePrefix - The table prefix (alias or name), or null for unqualified columnspublic int getChildCount()
public boolean isEmpty()
public static FromScopeIndex fromScope(IScope scope)
GlobalScope's name matcher
so vendor-specific identifier rules apply (S2).scope - The scope (SelectScope, UpdateScope, or FromScope)