@@ -20,7 +20,9 @@ use std::vec;
2020
2121use arrow_schema:: * ;
2222use datafusion_common:: { DFSchema , Result , TableReference } ;
23- use datafusion_expr:: test:: function_stub:: { count_udaf, max_udaf, min_udaf, sum_udaf} ;
23+ use datafusion_expr:: test:: function_stub:: {
24+ count_udaf, max_udaf, min_udaf, sum, sum_udaf,
25+ } ;
2426use datafusion_expr:: { col, lit, table_scan, wildcard, LogicalPlanBuilder } ;
2527use datafusion_functions:: unicode;
2628use datafusion_functions_aggregate:: grouping:: grouping_udaf;
@@ -563,6 +565,32 @@ Projection: unnest_placeholder(unnest_table.struct_col).field1, unnest_placehold
563565 Ok ( ( ) )
564566}
565567
568+ #[ test]
569+ fn test_aggregation_without_projection ( ) -> Result < ( ) > {
570+ let schema = Schema :: new ( vec ! [
571+ Field :: new( "name" , DataType :: Utf8 , false ) ,
572+ Field :: new( "age" , DataType :: UInt8 , false ) ,
573+ ] ) ;
574+
575+ let plan = LogicalPlanBuilder :: from (
576+ table_scan ( Some ( "users" ) , & schema, Some ( vec ! [ 0 , 1 ] ) ) ?. build ( ) ?,
577+ )
578+ . aggregate ( vec ! [ col( "name" ) ] , vec ! [ sum( col( "age" ) ) ] ) ?
579+ . build ( ) ?;
580+
581+ let unparser = Unparser :: default ( ) ;
582+ let statement = unparser. plan_to_sql ( & plan) ?;
583+
584+ let actual = & statement. to_string ( ) ;
585+
586+ assert_eq ! (
587+ actual,
588+ r#"SELECT sum(users.age), users."name" FROM (SELECT users."name", users.age FROM users) GROUP BY users."name""#
589+ ) ;
590+
591+ Ok ( ( ) )
592+ }
593+
566594#[ test]
567595fn test_table_references_in_plan_to_sql ( ) {
568596 fn test ( table_name : & str , expected_sql : & str , dialect : & impl UnparserDialect ) {
0 commit comments