You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Jefffrey (via GitHub)" <gi...@apache.org> on 2023/03/02 19:31:07 UTC

[GitHub] [arrow-datafusion] Jefffrey commented on issue #5444: Expr.alias function not work with count aggregation

Jefffrey commented on issue #5444:
URL: https://github.com/apache/arrow-datafusion/issues/5444#issuecomment-1452440185

   Yeah the reason is that `aggregate_statistics` physical optimizer rule sets the name of the output column like so:
   
   https://github.com/apache/arrow-datafusion/blob/f68214dc6553ede5f23ba54cac6150f4c1e18e8c/datafusion/core/src/physical_optimizer/aggregate_statistics.rs#L192-L196
   
   Ideally would take `casted_expr.name()` instead which would contain the alias you gave it. However what I've noticed is that it can contain the table as part of the name. So if it's switched to `casted_expr.name()` then following code:
   
   ```rust
   ctx
       .table("p")
       .await?
       .aggregate(vec![], vec![count(col("id"))])?
       .show().await?;
   ```
   
   Will output:
   
   ```
   +-------------+
   | COUNT(p.id) |
   +-------------+
   | 7300        |
   +-------------+
   ```
   
   Note the `p.id` instead of just `id`.
   
   P.S. this affects the other aggregate functions too, e.g.
   
   https://github.com/apache/arrow-datafusion/blob/f68214dc6553ede5f23ba54cac6150f4c1e18e8c/datafusion/core/src/physical_optimizer/aggregate_statistics.rs#L224


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org