geoffreyclaude opened a new pull request, #24756:
URL: https://github.com/apache/datafusion/pull/24756

   ## Which issue does this PR close?
   
   - Closes #24753.
   
   ## 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](https://github.com/Query-farm/vgi-datafusion/blob/c6e3a6cfb05202a61233aa535912d8e2faae3e6e/src/sampling.rs#L32-L65)
 and [returns the alias 
again](https://github.com/Query-farm/vgi-datafusion/blob/c6e3a6cfb05202a61233aa535912d8e2faae3e6e/src/sampling.rs#L131-L133).
   
   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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to