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).
| Constructor and Description |
|---|
FromScopeIndex(List<ScopeChild> children)
Creates an index from the given list of scope children.
|
| Modifier and Type | Method and Description |
|---|---|
ScopeChild |
findByAlias(String alias)
Finds a ScopeChild by its alias (case-insensitive).
|
ScopeChild |
findByQualifier(String qualifier)
Finds a ScopeChild by alias first, then by namespace name (case-insensitive).
|
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)
children - The list of ScopeChild from a FromScopepublic 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)
scope - The scope (SelectScope, UpdateScope, or FromScope)