@@ -25,7 +25,7 @@ use crate::type_coercion::functions::fields_with_udf;
2525use crate :: udf:: ReturnFieldArgs ;
2626use crate :: { LogicalPlan , Projection , Subquery , WindowFunctionDefinition , utils} ;
2727use arrow:: compute:: can_cast_types;
28- use arrow:: datatypes:: { DataType , Field } ;
28+ use arrow:: datatypes:: { DataType , Field , FieldRef } ;
2929use datafusion_common:: datatype:: FieldExt ;
3030use datafusion_common:: metadata:: FieldMetadata ;
3131use datafusion_common:: {
@@ -458,7 +458,7 @@ impl ExprSchemable for Expr {
458458 /// with the default implementation returning empty field metadata
459459 /// - **Aggregate functions**: Generate metadata via function's [`return_field`] method,
460460 /// with the default implementation returning empty field metadata
461- /// - **Window functions**: field metadata is empty
461+ /// - **Window functions**: field metadata follows the function's return field
462462 ///
463463 /// ## Table Reference Scoping
464464 /// - Establishes proper qualified field references when columns belong to specific tables
@@ -534,11 +534,7 @@ impl ExprSchemable for Expr {
534534 ) ) )
535535 }
536536 Expr :: WindowFunction ( window_function) => {
537- let ( dt, nullable) = self . data_type_and_nullable_with_window_function (
538- schema,
539- window_function,
540- ) ?;
541- Ok ( Arc :: new ( Field :: new ( & schema_name, dt, nullable) ) )
537+ self . window_function_field ( schema, window_function)
542538 }
543539 Expr :: AggregateFunction ( aggregate_function) => {
544540 let AggregateFunction {
@@ -703,6 +699,15 @@ impl Expr {
703699 schema : & dyn ExprSchema ,
704700 window_function : & WindowFunction ,
705701 ) -> Result < ( DataType , bool ) > {
702+ let return_field = self . window_function_field ( schema, window_function) ?;
703+ Ok ( ( return_field. data_type ( ) . clone ( ) , return_field. is_nullable ( ) ) )
704+ }
705+
706+ fn window_function_field (
707+ & self ,
708+ schema : & dyn ExprSchema ,
709+ window_function : & WindowFunction ,
710+ ) -> Result < FieldRef > {
706711 let WindowFunction {
707712 fun,
708713 params : WindowFunctionParams { args, .. } ,
@@ -738,9 +743,7 @@ impl Expr {
738743 . into_iter ( )
739744 . collect :: < Vec < _ > > ( ) ;
740745
741- let return_field = udaf. return_field ( & new_fields) ?;
742-
743- Ok ( ( return_field. data_type ( ) . clone ( ) , return_field. is_nullable ( ) ) )
746+ udaf. return_field ( & new_fields)
744747 }
745748 WindowFunctionDefinition :: WindowUDF ( udwf) => {
746749 let data_types = fields
@@ -769,7 +772,6 @@ impl Expr {
769772 let field_args = WindowUDFFieldArgs :: new ( & new_fields, & function_name) ;
770773
771774 udwf. field ( field_args)
772- . map ( |field| ( field. data_type ( ) . clone ( ) , field. is_nullable ( ) ) )
773775 }
774776 }
775777 }
0 commit comments