Class FromScopeIndex

Object
gudusoft.gsqlparser.resolver2.model.FromScopeIndex

public class FromScopeIndex extends Object
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 Details

    • FromScopeIndex

      public FromScopeIndex(List<ScopeChild> children)
      Creates an index from the given list of scope children.
      Parameters:
      children - The list of ScopeChild from a FromScope
  • Method Details

    • findByAlias

      public ScopeChild findByAlias(String alias)
      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

      public ScopeChild findByQualifier(String qualifier)
      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

      public TTable findTableByQualifier(String qualifier)
      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

      public int getChildCount()
      Gets the total number of children indexed.
      Returns:
      The child count
    • isEmpty

      public boolean isEmpty()
      Checks if the index is empty.
      Returns:
      true if no children are indexed
    • fromScope

      public static FromScopeIndex fromScope(IScope scope)
      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

      public String toString()
      Overrides:
      toString in class Object