Class CTEScope
Object
gudusoft.gsqlparser.resolver2.scope.AbstractScope
gudusoft.gsqlparser.resolver2.scope.ListBasedScope
gudusoft.gsqlparser.resolver2.scope.CTEScope
- All Implemented Interfaces:
IScope
Scope for Common Table Expressions (WITH clause).
Manages visibility of CTEs defined in a WITH clause.
Example:
WITH cte1 AS (SELECT id, name FROM users), cte2 AS (SELECT * FROM cte1 WHERE id > 100) -- can reference cte1 SELECT * FROM cte2; -- can reference both cte1 and cte2
Key features: - Multiple CTEs in same WITH clause - CTEs can reference earlier CTEs in the same WITH clause - Recursive CTE support (same CTE references itself) - CTEs are visible to the main query and to later CTEs
-
Field Summary
Fields inherited from class gudusoft.gsqlparser.resolver2.scope.ListBasedScope
childrenFields inherited from class gudusoft.gsqlparser.resolver2.scope.AbstractScope
node, parent, scopeType -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCTE(String cteName, CTENamespace cteNamespace) Add a CTE to this scope.Get all CTEs in this scope.Get a CTE namespace by name.intGet the number of CTEs in this scope.Get all recursive CTEs in this scope.booleanCheck if a CTE with the given name exists in this scope.booleanCheck if this scope contains a recursive CTE.resolveTable(String tableName) Resolve a table name, checking CTEs first before delegating to parent.toString()Methods inherited from class gudusoft.gsqlparser.resolver2.scope.ListBasedScope
addChild, getChildren, getVisibleNamespaces, resolve, resolveInNamespaceMethods inherited from class gudusoft.gsqlparser.resolver2.scope.AbstractScope
fullyQualify, getNode, getParent, getScopeType, isWithin
-
Constructor Details
-
CTEScope
-
-
Method Details
-
addCTE
Add a CTE to this scope. CTEs are added in order, allowing later CTEs to reference earlier ones.- Parameters:
cteName- the CTE name (alias)cteNamespace- the CTE namespace
-
hasCTE
Check if a CTE with the given name exists in this scope.- Parameters:
cteName- the CTE name to check- Returns:
- true if CTE exists, false otherwise
-
getCTE
Get a CTE namespace by name.- Parameters:
cteName- the CTE name- Returns:
- the CTENamespace, or null if not found
-
getAllCTEs
Get all CTEs in this scope.- Returns:
- list of all CTE namespaces in definition order
-
getCTECount
Get the number of CTEs in this scope.- Returns:
- CTE count
-
resolveTable
Resolve a table name, checking CTEs first before delegating to parent. This allows CTEs to shadow real tables.- Specified by:
resolveTablein interfaceIScope- Overrides:
resolveTablein classListBasedScope- Parameters:
tableName- the table name to resolve- Returns:
- the namespace for the CTE or table, or null if not found
-
hasRecursiveCTE
Check if this scope contains a recursive CTE. A recursive CTE is one that references itself in its definition.- Returns:
- true if any CTE in this scope is recursive
-
getRecursiveCTEs
Get all recursive CTEs in this scope.- Returns:
- list of recursive CTE namespaces
-
getCTEList
-
toString
- Overrides:
toStringin classListBasedScope
-