andygrove commented on issue #3353:
URL: https://github.com/apache/datafusion/issues/3353#issuecomment-7168037233

   Closing as not planned. This is still reproducible on main, but it is an 
edge case that is unlikely to come up in practice. It needs two aggregates in 
the same SELECT whose default display names collide, and an explicit alias on 
either one doesn't help.
   
   Current state:
   
   ```sql
   SELECT approx_distinct(c9) AS count_c9,
          approx_distinct(cast(c9 as varchar)) AS count_c9_str
   FROM aggregate_test_100;
   ```
   
   fails with `Schema contains duplicate unqualified field name 
"approx_distinct(aggregate_test_100.c9)"`. The equivalent DataFrame API query 
works.
   
   Cause, from the analysis above:
   - `find_aggregate_exprs()` in `datafusion/expr/src/utils.rs` matches only 
`Expr::AggregateFunction`, so the SQL planner strips aliases when it collects 
aggregates. Making it also match aliased aggregates fixes this query, but 
changes several plans, including some in `tpcds_planning`.
   - Even without aliases, the two expressions get the same display name 
because the cast does not appear in the name (#18975). Preserving aliases alone 
may not be a complete fix.
   
   `aggregate.slt` has a `statement error` test that covers this, so a fix will 
show up there. Anyone who runs into this in practice is welcome to reopen.


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