jiangzhx opened a new issue, #5444: URL: https://github.com/apache/arrow-datafusion/issues/5444
**Describe the bug** Expr.alias function not work with count aggregation,it's should be alias column name with origin column name `datafusion_expr::count(col(f.name())).alias(f.name()) `<img width="1796" alt="image" src="https://user-images.githubusercontent.com/494507/222323287-5e0e1978-b8a6-406b-b324-c58e04c8f684.png"> physical_plan ``` ProjectionExec: expr=[7300 as COUNT(id), 7300 as COUNT(tinyint_col), 7300 as COUNT(smallint_col), 7300 as COUNT(int_col), 7300 as COUNT(bigint_col), 7300 as COUNT(float_col), 7300 as COUNT(double_col), 7300 as COUNT(date_string_col), 7300 as COUNT(string_col), 7300 as COUNT(timestamp_col), 7300 as COUNT(year), 7300 as COUNT(month)] EmptyExec: produce_one_row=true ``` **To Reproduce** ``` #[tokio::test] async fn count_test() -> Result<()> { let ctx = SessionContext::new(); let testdata = datafusion::test_util::parquet_test_data(); let filename = &format!("{testdata}/alltypes_tiny_pages.parquet"); let df = ctx .read_parquet(filename, ParquetReadOptions::default()) .await?; let cnt = df .clone() .aggregate( vec![], df.schema() .fields() .iter() .clone() .filter(|f| !matches!(f.data_type(), DataType::Boolean)) // wrong result,alias column with count like "count(id)" .map(|f| datafusion_expr::count(col(f.name())).alias(f.name())) // right result,alias column with origin table name // .map(|f| datafusion_expr::max(col(f.name())).alias(f.name())) // right result,alias column with origin table name // .map(|f| datafusion_expr::count_distinct(col(f.name())).alias(f.name())) .collect::<Vec<_>>(), ) .unwrap(); print_batches(&cnt.clone().collect().await.unwrap()).expect("panic message"); let plan = cnt.create_physical_plan().await.unwrap(); let displayable_plan = displayable(plan.as_ref()); let plan_string = format!("{}", displayable_plan.indent()); println!("{}", plan_string); Ok(()) } ``` **Expected behavior** right result,alias column name with origin column name `.map(|f| datafusion_expr::max(col(f.name())).alias(f.name()))` <img width="1456" alt="image" src="https://user-images.githubusercontent.com/494507/222323990-fddf64de-b43c-4f9c-909b-e8b45b080832.png"> physical_plan ``` AggregateExec: mode=Final, gby=[], aggr=[id, tinyint_col, smallint_col, int_col, bigint_col, float_col, double_col, date_string_col, string_col, timestamp_col, year, month] AggregateExec: mode=Partial, gby=[], aggr=[id, tinyint_col, smallint_col, int_col, bigint_col, float_col, double_col, date_string_col, string_col, timestamp_col, year, month] ParquetExec: limit=None, partitions={1 group: [[Users/sylar/workspace/opensource/arrow-datafusion/parquet-testing/data/alltypes_tiny_pages.parquet]]}, projection=[id, tinyint_col, smallint_col, int_col, bigint_col, float_col, double_col, date_string_col, string_col, timestamp_col, year, month] ``` **Additional context** Add any other context about the problem here. -- 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]
