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

   ### Describe the bug
   
   The `SingleDistinctToGroupBy` optimizer rule rewrites a grouped 
count(DISTINCT col) into a cheaper nested double aggregate. It fires for plans 
built by the SQL planner but not for the logically-equivalent plan built by the 
DataFrame API, so the DataFrame path runs materially slower for the same query.
   
   The divergence is caused by how each front-end places the output alias:
     - SQL (count(DISTINCT v) AS n): the alias becomes an outer Projection; 
Aggregate.aggr_expr holds a bare Expr::AggregateFunction.
     - DataFrame API (count(col("v")).distinct().alias("n")): the alias wraps 
the aggregate directly, so aggr_expr holds Expr::Alias(AggregateFunction).
   
   `is_single_distinct_agg` only matches a bare Expr::AggregateFunction and 
returns false for the aliased shape, so the rule never fires for the DataFrame 
API.
   
   ### To Reproduce
   
   _No response_
   
   ### Expected behavior
   
   _No response_
   
   ### Additional context
   
   _No response_


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