feat(sql): expose CTE scope to relation planners - #24755
Open
geoffreyclaude wants to merge 1 commit into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24755 +/- ##
==========================================
+ Coverage 81.48% 81.58% +0.09%
==========================================
Files 1122 1123 +1
Lines 404248 406621 +2373
Branches 404248 406621 +2373
==========================================
+ Hits 329390 331726 +2336
+ Misses 55547 55455 -92
- Partials 19311 19440 +129 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
geoffreyclaude
marked this pull request as ready for review
August 31, 2026 13:43
Contributor
Author
|
@phas02 would you mind reviewing this PR? |
geoffreyclaude
force-pushed
the
codex/relation-cte-scope
branch
from
August 31, 2026 15:00
baa6bdc to
a70e61a
Compare
phas02
reviewed
Aug 31, 2026
phas02
left a comment
There was a problem hiding this comment.
Looks good from a requirements point of view, exactly what we wanted. The implementation in DataFusion and rust is simple and low risk.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
RelationPlannerextensions run before DataFusion's built-in CTE lookup. That ordering is useful, but it leaves a name-based extension unable to tell that DataFusion would resolve a same-named relation as a CTE. Both plans can be valid, so the mistake is silent: the user asks for the CTE and gets the extension relation instead.Downstream projects have had to rebuild this context themselves. For example, GlossQL collects CTE names in a pre-pass. Its comment captures the rough edge nicely: because the extension cannot ask DataFusion about the current scope, a CTE declared only inside one subquery may have to be treated as visible everywhere.
DataFusion already has the precise, lexical CTE scope while it plans the query. This PR makes that information available to the extension that needs it.
What changes are included in this PR?
RelationPlannerContext::get_cte(&TableReference), with a defaultNoneimplementation so existing custom context implementations remain source-compatible.RelationPlanning::Originalso planning continues through the remaining planner chain.The lookup remains opt-in. Every ordinary name-based planner in a chain should perform the check to preserve DataFusion's built-in CTE resolution, while planners with deliberately reserved names or custom syntax can keep their existing precedence.
Are these changes tested?
Yes. The integration tests cover:
I also ran
cargo fmt --all, the required all-target/all-feature Clippy command with warnings denied, the focused relation-planner tests, the documentation Prettier check, and the required extended workspace test suite.Are there any user-facing changes?
This adds a small public API for relation-planner authors. It is source-compatible because the trait method has a default implementation. Existing planners keep their current behavior until they opt into the CTE check; planners that do opt in can preserve DataFusion's existing CTE resolution without re-parsing the statement or approximating lexical scope.