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 Summary
Modifier and TypeMethodDescriptionvoidaddChild(INamespace namespace, String alias, boolean nullable) Add a child namespace to this scope.fullyQualify(String name) Fully qualify a name based on this scope.Get all child namespaces in this scope.getNode()Get the associated AST nodeGet the parent scope.Get the scope typeGet all namespaces visible in this scope.booleanCheck if this scope is within (nested inside) another scope.voidresolve(List<String> names, INameMatcher matcher, boolean deep, IResolved resolved) Resolve a qualified or unqualified name.resolveTable(String tableName) Resolve a table name or alias to its namespace.
-
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
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 rulesdeep- Whether to recursively resolve into record fieldsresolved- 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
Add a child namespace to this scope. Typically used in FROM clauses to add tables/subqueries.- Parameters:
namespace- The namespace to addalias- The alias for this namespacenullable- 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
Check if this scope is within (nested inside) another scope.- Parameters:
ancestorScope- Potential ancestor scope- Returns:
- true if this scope is nested within ancestorScope
-