@@ -1005,7 +1005,10 @@ impl OptimizerRule for PushDownFilter {
10051005 let extract_partition_keys = |func : & WindowFunction | {
10061006 func. partition_by
10071007 . iter ( )
1008- . map ( |c| Column :: from_qualified_name ( c. schema_name ( ) . to_string ( ) ) )
1008+ . map ( |c| {
1009+ let ( relation, name) = c. qualified_name ( ) ;
1010+ Column :: new ( relation, name)
1011+ } )
10091012 . collect :: < HashSet < _ > > ( )
10101013 } ;
10111014 let potential_partition_keys = window
@@ -1562,6 +1565,38 @@ mod tests {
15621565 assert_optimized_plan_eq ( plan, expected)
15631566 }
15641567
1568+ /// verifies that filters with unusual identifier names are pushed down through window functions
1569+ #[ test]
1570+ fn filter_window_special_identifier ( ) -> Result < ( ) > {
1571+ let schema = Schema :: new ( vec ! [
1572+ Field :: new( "$a" , DataType :: UInt32 , false ) ,
1573+ Field :: new( "$b" , DataType :: UInt32 , false ) ,
1574+ Field :: new( "$c" , DataType :: UInt32 , false ) ,
1575+ ] ) ;
1576+ let table_scan = table_scan ( Some ( "test" ) , & schema, None ) ?. build ( ) ?;
1577+
1578+ let window = Expr :: WindowFunction ( WindowFunction :: new (
1579+ WindowFunctionDefinition :: WindowUDF (
1580+ datafusion_functions_window:: rank:: rank_udwf ( ) ,
1581+ ) ,
1582+ vec ! [ ] ,
1583+ ) )
1584+ . partition_by ( vec ! [ col( "$a" ) , col( "$b" ) ] )
1585+ . order_by ( vec ! [ col( "$c" ) . sort( true , true ) ] )
1586+ . build ( )
1587+ . unwrap ( ) ;
1588+
1589+ let plan = LogicalPlanBuilder :: from ( table_scan)
1590+ . window ( vec ! [ window] ) ?
1591+ . filter ( col ( "$b" ) . gt ( lit ( 10i64 ) ) ) ?
1592+ . build ( ) ?;
1593+
1594+ let expected = "\
1595+ WindowAggr: windowExpr=[[rank() PARTITION BY [test.$a, test.$b] ORDER BY [test.$c ASC NULLS FIRST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW]]\
1596+ \n TableScan: test, full_filters=[test.$b > Int64(10)]";
1597+ assert_optimized_plan_eq ( plan, expected)
1598+ }
1599+
15651600 /// verifies that when partitioning by 'a' and 'b', and filtering by 'a' and 'b', both 'a' and
15661601 /// 'b' are pushed
15671602 #[ test]
0 commit comments