@@ -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:: {
@@ -156,9 +156,10 @@ impl ExprSchemable for Expr {
156156 let return_type = self . to_field ( schema) ?. 1 . data_type ( ) . clone ( ) ;
157157 Ok ( return_type)
158158 }
159- Expr :: WindowFunction ( window_function) => self
160- . data_type_and_nullable_with_window_function ( schema, window_function)
161- . map ( |( return_type, _) | return_type) ,
159+ Expr :: WindowFunction ( window_function) => Ok ( self
160+ . window_function_field ( schema, window_function) ?
161+ . data_type ( )
162+ . clone ( ) ) ,
162163 Expr :: AggregateFunction ( AggregateFunction {
163164 func,
164165 params : AggregateFunctionParams { args, .. } ,
@@ -357,12 +358,9 @@ impl ExprSchemable for Expr {
357358 Expr :: AggregateFunction ( AggregateFunction { func, .. } ) => {
358359 Ok ( func. is_nullable ( ) )
359360 }
360- Expr :: WindowFunction ( window_function) => self
361- . data_type_and_nullable_with_window_function (
362- input_schema,
363- window_function,
364- )
365- . map ( |( _, nullable) | nullable) ,
361+ Expr :: WindowFunction ( window_function) => Ok ( self
362+ . window_function_field ( input_schema, window_function) ?
363+ . is_nullable ( ) ) ,
366364 Expr :: ScalarVariable ( field, _) => Ok ( field. is_nullable ( ) ) ,
367365 Expr :: TryCast { .. } | Expr :: Unnest ( _) | Expr :: Placeholder ( _) => Ok ( true ) ,
368366 Expr :: IsNull ( _)
@@ -458,7 +456,7 @@ impl ExprSchemable for Expr {
458456 /// with the default implementation returning empty field metadata
459457 /// - **Aggregate functions**: Generate metadata via function's [`return_field`] method,
460458 /// with the default implementation returning empty field metadata
461- /// - **Window functions**: field metadata is empty
459+ /// - **Window functions**: field metadata follows the function's return field
462460 ///
463461 /// ## Table Reference Scoping
464462 /// - Establishes proper qualified field references when columns belong to specific tables
@@ -534,11 +532,7 @@ impl ExprSchemable for Expr {
534532 ) ) )
535533 }
536534 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) ) )
535+ self . window_function_field ( schema, window_function)
542536 }
543537 Expr :: AggregateFunction ( aggregate_function) => {
544538 let AggregateFunction {
@@ -698,11 +692,11 @@ impl Expr {
698692 ///
699693 /// Otherwise, returns an error if there's a type mismatch between
700694 /// the window function's signature and the provided arguments.
701- fn data_type_and_nullable_with_window_function (
695+ fn window_function_field (
702696 & self ,
703697 schema : & dyn ExprSchema ,
704698 window_function : & WindowFunction ,
705- ) -> Result < ( DataType , bool ) > {
699+ ) -> Result < FieldRef > {
706700 let WindowFunction {
707701 fun,
708702 params : WindowFunctionParams { args, .. } ,
@@ -738,9 +732,7 @@ impl Expr {
738732 . into_iter ( )
739733 . collect :: < Vec < _ > > ( ) ;
740734
741- let return_field = udaf. return_field ( & new_fields) ?;
742-
743- Ok ( ( return_field. data_type ( ) . clone ( ) , return_field. is_nullable ( ) ) )
735+ udaf. return_field ( & new_fields)
744736 }
745737 WindowFunctionDefinition :: WindowUDF ( udwf) => {
746738 let data_types = fields
@@ -769,7 +761,6 @@ impl Expr {
769761 let field_args = WindowUDFFieldArgs :: new ( & new_fields, & function_name) ;
770762
771763 udwf. field ( field_args)
772- . map ( |field| ( field. data_type ( ) . clone ( ) , field. is_nullable ( ) ) )
773764 }
774765 }
775766 }
0 commit comments