@@ -1321,7 +1321,7 @@ mod tests {
13211321 }
13221322
13231323 #[ test]
1324- fn test_unsupported_distinct_handling_is_not_rewritten ( ) {
1324+ fn test_unsupported_distinct_handling_is_rewritten ( ) {
13251325 let table_scan = test_table_scan ( ) . unwrap ( ) ;
13261326
13271327 // approx_median returns DistinctHandling::Unsupported
@@ -1335,22 +1335,23 @@ mod tests {
13351335 ) ) ;
13361336
13371337 let plan = LogicalPlanBuilder :: from ( table_scan)
1338- . aggregate ( vec ! [ col( "a" ) ] , vec ! [ aggr_expr] )
1338+ . aggregate ( vec ! [ col( "a" ) ] , vec ! [ aggr_expr, sum ( col ( "c" ) ) ] )
13391339 . unwrap ( )
13401340 . build ( )
13411341 . unwrap ( ) ;
13421342
13431343 // The rule should rewrite the plan because approx_median doesn't support DISTINCT natively,
1344- // so it requires SingleDistinctToGroupBy to deduplicate the input.
1344+ // so it requires SingleDistinctToGroupBy to deduplicate the input even when accompanied
1345+ // by non-distinct aggregates.
13451346 let rule: Arc < dyn OptimizerRule + Send + Sync > =
13461347 Arc :: new ( SingleDistinctToGroupBy :: new ( ) ) ;
13471348 assert_optimized_plan_eq_display_indent_snapshot ! (
13481349 rule,
13491350 plan,
13501351 @r"
1351- Projection: test.a, approx_median(alias1) AS approx_median(DISTINCT test.b) [a:UInt32, approx_median(DISTINCT test.b):Float64;N]
1352- Aggregate: groupBy=[[test.a]], aggr=[[approx_median(alias1)]] [a:UInt32, approx_median(alias1):Float64;N]
1353- Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[]] [a:UInt32, alias1:UInt32]
1352+ Projection: test.a, approx_median(alias1) AS approx_median(DISTINCT test.b), sum(alias2) AS sum(test.c) [a:UInt32, approx_median(DISTINCT test.b):Float64;N, sum(test.c):UInt64 ;N]
1353+ Aggregate: groupBy=[[test.a]], aggr=[[approx_median(alias1), sum(alias2) ]] [a:UInt32, approx_median(alias1):Float64;N, sum(alias2):UInt64 ;N]
1354+ Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[sum(test.c) AS alias2 ]] [a:UInt32, alias1:UInt32, alias2:UInt64;N ]
13541355 TableScan: test [a:UInt32, b:UInt32, c:UInt32]
13551356 " ,
13561357 ) . unwrap ( ) ;
0 commit comments