Skip to content

fix(examples): apply relation aliases once - #24756

Draft
geoffreyclaude wants to merge 2 commits into
apache:mainfrom
geoffreyclaude:codex/relation-alias-once
Draft

fix(examples): apply relation aliases once#24756
geoffreyclaude wants to merge 2 commits into
apache:mainfrom
geoffreyclaude:codex/relation-alias-once

Conversation

@geoffreyclaude

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

The official TABLESAMPLE relation-planner example currently applies a relation alias twice. It recursively plans the underlying table while the alias is still attached, then returns that same alias with the completed sampled plan. RelationPlannerContext::plan(...) applies the first copy, and DataFusion applies PlannedRelation::alias a second time.

This is subtle enough to miss in review, and the example is doing its job a little too well: VGI copied the same recursive-planning shape and returns the alias again.

The intended ownership rule is simple: remove the outer alias before recursively planning an inner relation, then return that alias with the finished extension plan so DataFusion applies it once, around the whole relation.

What changes are included in this PR?

  • Repair the TABLESAMPLE example so the recursively planned base relation has no alias.
  • Explain alias ownership in the PlannedRelation and RelationPlannerContext::plan API docs and in the extending-SQL guide.
  • Repair the guide's stale RelationPlanning example to use the current boxed variants.
  • Add a regression test for an alias with a column list.

Are these changes tested?

Yes. The test checks the complete logical-plan shape and verifies that the relation alias and each column rename appear exactly once. As an ablation check, restoring the old alias.clone() line makes the test fail with two SubqueryAlias nodes and duplicate rename projections.

I also ran the focused example test, example compilation, cargo fmt --all, the required all-target/all-feature Clippy command with warnings denied, Rustdoc for datafusion-expr, and the documentation Prettier check.

Are there any user-facing changes?

The core planner's alias behavior is unchanged. The user-facing changes are a corrected official example and clearer documentation for extension authors.

@github-actions github-actions Bot added documentation Improvements or additions to documentation logical-expr Logical plan and expressions labels Aug 28, 2026
@codecov-commenter

codecov-commenter commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.48%. Comparing base (4d3e79e) to head (9e3f228).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24756      +/-   ##
==========================================
- Coverage   81.48%   81.48%   -0.01%     
==========================================
  Files        1122     1122              
  Lines      404248   404248              
  Branches   404248   404248              
==========================================
- Hits       329390   329386       -4     
  Misses      55547    55547              
- Partials    19311    19315       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

RelationPlanning::Planned and RelationPlanning::Original began taking boxed values in apache@e8efd59, merged through apache#19672. The extending SQL guide retained the old constructors, so update the example to match the current API.
@geoffreyclaude
geoffreyclaude force-pushed the codex/relation-alias-once branch from 6c73d46 to 9e3f228 Compare August 28, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation logical-expr Logical plan and expressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RelationPlanner TABLESAMPLE example applies relation aliases twice

2 participants