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

   ### Describe the bug
   
   Split out from #26969 as a follow-up (related to #25449, which tracks 
replacing the string-prefix protocol with a typed marker).
   
   While #26969 fixes placement-based classification (`is_extracted_alias`) and 
canonical-ID seeding (`extracted_expr_id`), name collisions can still occur 
when user columns or aliases use the reserved `__datafusion_extracted` prefix:
   
   1. **Alias allocation collisions / wraparound**: When existing 
`__datafusion_extracted*` names are near `usize::MAX` (causing `AliasGenerator` 
wraparound to `_MAX` / `_0`) or when `PushDownLeafProjections` runs without 
`ExtractLeafExpressions`, newly allocated extraction aliases can collide with 
existing column or alias names.
   2. **Input-column shadowing**: When a projection aliases a pushdown-eligible 
expression to a `__datafusion_extracted*` name that already exists in its input 
schema (and the input column is also referenced), pushing that alias down 
directly causes an `AmbiguousReference` / duplicate field error:
   
      ```sql
      CREATE TABLE t AS
      SELECT column1 AS __datafusion_extracted_manual, column2 AS s
      FROM VALUES (0, {a: 1}), (1, {a: 2});
   
      SELECT s['a'] AS __datafusion_extracted_manual
      FROM t
      WHERE t.__datafusion_extracted_manual > 0;
      ```
   
   3. **Destination branch collisions (e.g., `UNION ALL`)**: Carrying a 
`__datafusion_extracted*` alias down across a set operation or join can collide 
with a column of the same name present only in another branch/side.
   
   ### Expected behavior
   
   Queries using columns or aliases with the `__datafusion_extracted` prefix 
should not fail with schema ambiguity errors, and collision avoidance should 
not regress leaf pushdown for ordinary queries (such as `LEFT SEMI` Parquet 
leaf pushdown).
   
   ### Design notes
   
   As discussed in #26969, adding ad-hoc destination checks at multiple sites 
duplicates merge-builder decisions and risks regressing unrelated pushdowns. 
Possible directions:
   
   - Handle collisions in a single place: reserve all existing 
`__datafusion_extracted*` names across the entire plan upfront, re-extract 
under a fresh plan-wide unique name instead of moving a potentially colliding 
alias down, and skip extraction instead of wrapping when no free name is 
available (verifying how this interacts with optimizer-generated aliases from 
earlier passes).
   - Or track this as a known limitation of the reserved prefix until #25449 
introduces a typed marker.
   


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