@@ -29,6 +29,7 @@ use datafusion_common::tree_node::{
2929use datafusion_common:: {
3030 internal_err, plan_err, qualified_name, Column , DFSchema , Result ,
3131} ;
32+ use datafusion_expr:: expr:: WindowFunction ;
3233use datafusion_expr:: expr_rewriter:: replace_col;
3334use datafusion_expr:: logical_plan:: { Join , JoinType , LogicalPlan , TableScan , Union } ;
3435use datafusion_expr:: utils:: {
@@ -1001,23 +1002,34 @@ impl OptimizerRule for PushDownFilter {
10011002 // multiple window functions, each with potentially different partition keys.
10021003 // Therefore, we need to ensure that any potential partition key returned is used in
10031004 // ALL window functions. Otherwise, filters cannot be pushed by through that column.
1005+ let extract_partition_keys = |func : & WindowFunction | {
1006+ func. partition_by
1007+ . iter ( )
1008+ . map ( |c| Column :: from_qualified_name ( c. schema_name ( ) . to_string ( ) ) )
1009+ . collect :: < HashSet < _ > > ( )
1010+ } ;
10041011 let potential_partition_keys = window
10051012 . window_expr
10061013 . iter ( )
10071014 . map ( |e| {
1008- if let Expr :: WindowFunction ( window_expression) = e {
1009- window_expression
1010- . partition_by
1011- . iter ( )
1012- . map ( |c| {
1013- Column :: from_qualified_name (
1014- c. schema_name ( ) . to_string ( ) ,
1015- )
1016- } )
1017- . collect :: < HashSet < _ > > ( )
1018- } else {
1019- // window functions expressions are only Expr::WindowFunction
1020- unreachable ! ( )
1015+ match e {
1016+ Expr :: WindowFunction ( window_func) => {
1017+ extract_partition_keys ( window_func)
1018+ }
1019+ Expr :: Alias ( alias) => {
1020+ if let Expr :: WindowFunction ( window_func) =
1021+ alias. expr . as_ref ( )
1022+ {
1023+ extract_partition_keys ( window_func)
1024+ } else {
1025+ // window functions expressions are only Expr::WindowFunction
1026+ unreachable ! ( )
1027+ }
1028+ }
1029+ _ => {
1030+ // window functions expressions are only Expr::WindowFunction
1031+ unreachable ! ( )
1032+ }
10211033 }
10221034 } )
10231035 // performs the set intersection of the partition keys of all window functions,
0 commit comments