Class FromScopeIndex
Object
gudusoft.gsqlparser.resolver2.model.FromScopeIndex
Index structure for fast lookups in FromScope.
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).
- Since:
- 3.1.0.9
-
Constructor Summary
ConstructorsConstructorDescriptionFromScopeIndex(List<ScopeChild> children) Creates an index from the given list of scope children. -
Method Summary
Modifier and TypeMethodDescriptionfindByAlias(String alias) Finds a ScopeChild by its alias (case-insensitive).findByQualifier(String qualifier) Finds a ScopeChild by alias first, then by namespace name (case-insensitive).findCandidateNamespace(String tablePrefix) Finds a candidate namespace for column resolution.findTableByQualifier(String qualifier) Gets the TTable from a ScopeChild by qualifier, if the namespace represents a table.static FromScopeIndexCreates an index from a scope, extracting the FromScope if needed.intGets the total number of children indexed.Gets the first namespace that supports star columns or dynamic inference.booleanisEmpty()Checks if the index is empty.toString()
-
Constructor Details
-
FromScopeIndex
Creates an index from the given list of scope children.- Parameters:
children- The list of ScopeChild from a FromScope
-
-
Method Details
-
findByAlias
Finds a ScopeChild by its alias (case-insensitive).- Parameters:
alias- The alias to search for- Returns:
- The matching ScopeChild, or null if not found
-
findByQualifier
Finds a ScopeChild by alias first, then by namespace name (case-insensitive).- Parameters:
qualifier- The qualifier (alias or table name) to search for- Returns:
- The matching ScopeChild, or null if not found
-
findTableByQualifier
Gets the TTable from a ScopeChild by qualifier, if the namespace represents a table.- Parameters:
qualifier- The qualifier (alias or table name) to search for- Returns:
- The TTable if found and the namespace is a table, null otherwise
-
getPreferredStarNamespace
Gets the first namespace that supports star columns or dynamic inference. Used for resolving unqualified column references.- Returns:
- The preferred star namespace, or null if none exists
-
findCandidateNamespace
Finds a candidate namespace for column resolution.If a table prefix is provided, looks up by that prefix. Otherwise, returns the first star/dynamic namespace for unqualified columns.
- Parameters:
tablePrefix- The table prefix (alias or name), or null for unqualified columns- Returns:
- The candidate namespace, or null if not found
-
getChildCount
Gets the total number of children indexed.- Returns:
- The child count
-
isEmpty
Checks if the index is empty.- Returns:
- true if no children are indexed
-
fromScope
Creates an index from a scope, extracting the FromScope if needed.- Parameters:
scope- The scope (SelectScope, UpdateScope, or FromScope)- Returns:
- A new FromScopeIndex, or null if no FromScope is found
-
toString
-