@@ -34,8 +34,8 @@ use datafusion_common::{
3434 exec_datafusion_err, exec_err, DataFusionError , Result , ScalarValue ,
3535} ;
3636use datafusion_expr:: {
37- BuiltInWindowFunction , PartitionEvaluator , WindowFrame , WindowFunctionDefinition ,
38- WindowUDF ,
37+ BuiltInWindowFunction , PartitionEvaluator , ReversedUDWF , WindowFrame ,
38+ WindowFunctionDefinition , WindowUDF ,
3939} ;
4040use datafusion_physical_expr:: aggregate:: { AggregateExprBuilder , AggregateFunctionExpr } ;
4141use datafusion_physical_expr:: equivalence:: collapse_lex_req;
@@ -130,7 +130,7 @@ pub fn create_window_expr(
130130 }
131131 // TODO: Ordering not supported for Window UDFs yet
132132 WindowFunctionDefinition :: WindowUDF ( fun) => Arc :: new ( BuiltInWindowExpr :: new (
133- create_udwf_window_expr ( fun, args, input_schema, name) ?,
133+ create_udwf_window_expr ( fun, args, input_schema, name, ignore_nulls ) ?,
134134 partition_by,
135135 order_by,
136136 window_frame,
@@ -329,6 +329,7 @@ fn create_udwf_window_expr(
329329 args : & [ Arc < dyn PhysicalExpr > ] ,
330330 input_schema : & Schema ,
331331 name : String ,
332+ ignore_nulls : bool ,
332333) -> Result < Arc < dyn BuiltInWindowFunctionExpr > > {
333334 // need to get the types into an owned vec for some reason
334335 let input_types: Vec < _ > = args
@@ -341,6 +342,8 @@ fn create_udwf_window_expr(
341342 args : args. to_vec ( ) ,
342343 input_types,
343344 name,
345+ is_reversed : false ,
346+ ignore_nulls,
344347 } ) )
345348}
346349
@@ -353,6 +356,12 @@ struct WindowUDFExpr {
353356 name : String ,
354357 /// Types of input expressions
355358 input_types : Vec < DataType > ,
359+ /// This is set to `true` only if the user-defined window function
360+ /// expression supports evaluation in reverse order, and the
361+ /// evaluation order is reversed.
362+ is_reversed : bool ,
363+ /// Set to `true` if `IGNORE NULLS` is defined, `false` otherwise.
364+ ignore_nulls : bool ,
356365}
357366
358367impl BuiltInWindowFunctionExpr for WindowUDFExpr {
@@ -378,7 +387,18 @@ impl BuiltInWindowFunctionExpr for WindowUDFExpr {
378387 }
379388
380389 fn reverse_expr ( & self ) -> Option < Arc < dyn BuiltInWindowFunctionExpr > > {
381- None
390+ match self . fun . reverse_expr ( ) {
391+ ReversedUDWF :: Identical => Some ( Arc :: new ( self . clone ( ) ) ) ,
392+ ReversedUDWF :: NotSupported => None ,
393+ ReversedUDWF :: Reversed ( fun) => Some ( Arc :: new ( WindowUDFExpr {
394+ fun,
395+ args : self . args . clone ( ) ,
396+ name : self . name . clone ( ) ,
397+ input_types : self . input_types . clone ( ) ,
398+ is_reversed : !self . is_reversed ,
399+ ignore_nulls : self . ignore_nulls ,
400+ } ) ) ,
401+ }
382402 }
383403
384404 fn get_result_ordering ( & self , schema : & SchemaRef ) -> Option < PhysicalSortExpr > {
0 commit comments