Interface IScope

All Known Implementing Classes:
AbstractScope, CTEScope, DeleteScope, EmptyScope, FromScope, GlobalScope, GroupByScope, HavingScope, JoinScope, ListBasedScope, MergeScope, OraclePackageScope, OrderByScope, PlsqlBlockScope, SelectScope, UpdateScope

public interface IScope
Represents a name resolution scope in SQL. Each scope defines what names (tables, columns, CTEs) are visible at a given point. Design based on: - Apache Calcite's SqlValidatorScope - Classic compiler scope chain Key concepts: 1. Delegation: Most scopes delegate unknown names to parent scope 2. Hierarchy: Scopes form a tree matching SQL structure 3. Children: FROM clause scopes contain table/subquery children
  • Method Details

    • getParent

      Get the parent scope. Root scope (GlobalScope) has EmptyScope as parent.
      Returns:
      Parent scope, never null
    • getNode

      Get the associated AST node
      Returns:
      AST node for this scope
    • getScopeType

      Get the scope type
      Returns:
      Scope type enum
    • resolve

      void resolve(List<String> names, INameMatcher matcher, boolean deep, IResolved resolved)
      Resolve a qualified or unqualified name. This is the core method for name resolution.
      Parameters:
      names - Name parts (e.g., ["schema", "table", "column"])
      matcher - Name matcher for case sensitivity rules
      deep - Whether to recursively resolve into record fields
      resolved - Callback to collect all matches
    • resolveTable

      Resolve a table name or alias to its namespace.
      Parameters:
      tableName - Table name or alias
      Returns:
      Namespace if found, null otherwise
    • addChild

      void addChild(INamespace namespace, String alias, boolean nullable)
      Add a child namespace to this scope. Typically used in FROM clauses to add tables/subqueries.
      Parameters:
      namespace - The namespace to add
      alias - The alias for this namespace
      nullable - Whether this namespace is nullable (e.g., RIGHT side of LEFT JOIN)
    • getChildren

      Get all child namespaces in this scope.
      Returns:
      List of scope children
    • getVisibleNamespaces

      Get all namespaces visible in this scope. Includes children and namespaces from parent scopes.
      Returns:
      List of visible namespaces
    • fullyQualify

      Fully qualify a name based on this scope. E.g., "col" -> "table.col" if only one table has that column
      Parameters:
      name - Name to qualify
      Returns:
      Qualified name
    • isWithin

      boolean isWithin(IScope ancestorScope)
      Check if this scope is within (nested inside) another scope.
      Parameters:
      ancestorScope - Potential ancestor scope
      Returns:
      true if this scope is nested within ancestorScope