geoffreyclaude opened a new issue, #24753:
URL: https://github.com/apache/datafusion/issues/24753

   ## Describe the bug
   
   The official `RelationPlanner` `TABLESAMPLE` example recursively plans the 
underlying table with its alias still attached, then returns the same alias in 
`PlannedRelation`.
   
   Those two APIs both apply aliases:
   
   1. `RelationPlannerContext::plan(...)` applies the alias on the inner 
relation.
   2. DataFusion applies `PlannedRelation::alias` around the completed 
extension plan.
   
   As a result, an alias with a column list is represented twice in the logical 
plan. Besides making the plan noisy, the duplicate projections make the example 
a risky pattern for downstream implementations to copy.
   
   That has already happened in the wild: [VGI's sampling planner follows the 
example's recursive-planning 
pattern](https://github.com/Query-farm/vgi-datafusion/blob/c6e3a6cfb05202a61233aa535912d8e2faae3e6e/src/sampling.rs#L32-L65)
 and [returns the alias again with the completed 
plan](https://github.com/Query-farm/vgi-datafusion/blob/c6e3a6cfb05202a61233aa535912d8e2faae3e6e/src/sampling.rs#L131-L133).
   
   ## To reproduce
   
   Run the example planner with an alias that renames columns:
   
   ```sql
   SELECT *
   FROM sample_data AS sampled(first, second)
   TABLESAMPLE (3 ROWS)
   ```
   
   The logical plan contains two `SubqueryAlias: sampled` nodes and two alias 
projections.
   
   ## Expected behavior
   
   The example should remove the outer alias before recursively planning the 
underlying table, then return that alias with the completed sampled plan. The 
logical plan should contain one relation alias and one column-renaming 
projection.
   
   The public API docs and user guide should state this ownership rule clearly 
so extension authors know which layer applies the alias.
   
   ## Additional context
   
   This is an example and documentation repair; the core alias application 
behavior does not need to change.
   


-- 
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