@@ -32,7 +32,6 @@ use arrow::record_batch::RecordBatch;
3232use datafusion_common:: utils:: evaluate_partition_ranges;
3333use datafusion_common:: { Result , ScalarValue } ;
3434use datafusion_expr:: WindowFrame ;
35- use datafusion_expr:: window_frame:: WindowFrameBoundsComparators ;
3635use datafusion_expr:: window_state:: { WindowAggState , WindowFrameContext } ;
3736use datafusion_physical_expr_common:: sort_expr:: PhysicalSortExpr ;
3837
@@ -43,8 +42,6 @@ pub struct StandardWindowExpr {
4342 partition_by : Vec < Arc < dyn PhysicalExpr > > ,
4443 order_by : Vec < PhysicalSortExpr > ,
4544 window_frame : Arc < WindowFrame > ,
46- schema : SchemaRef ,
47- frame_comparators : Option < WindowFrameBoundsComparators > ,
4845}
4946
5047impl StandardWindowExpr {
@@ -54,22 +51,12 @@ impl StandardWindowExpr {
5451 partition_by : & [ Arc < dyn PhysicalExpr > ] ,
5552 order_by : & [ PhysicalSortExpr ] ,
5653 window_frame : Arc < WindowFrame > ,
57- schema : SchemaRef ,
5854 ) -> Self {
59- let frame_comparators = {
60- let cols: Option < Vec < _ > > = order_by
61- . iter ( )
62- . map ( |o| o. expr . data_type ( & schema) . ok ( ) . map ( |dt| ( dt, o. options ) ) )
63- . collect ( ) ;
64- cols. and_then ( |c| WindowFrameBoundsComparators :: new ( & window_frame, & c) )
65- } ;
6655 Self {
6756 expr,
6857 partition_by : partition_by. to_vec ( ) ,
6958 order_by : order_by. to_vec ( ) ,
7059 window_frame,
71- schema,
72- frame_comparators,
7360 }
7461 }
7562
@@ -139,7 +126,7 @@ impl WindowExpr for StandardWindowExpr {
139126
140127 let mut window_frame_ctx = WindowFrameContext :: new (
141128 Arc :: clone ( & self . window_frame ) ,
142- self . frame_comparators . clone ( ) ,
129+ self . build_frame_bounds_comparators ( batch . schema_ref ( ) ) ? ,
143130 ) ;
144131 let mut last_range = Range { start : 0 , end : 0 } ;
145132
@@ -170,6 +157,7 @@ impl WindowExpr for StandardWindowExpr {
170157 /// stateful, bounded-memory implementations.
171158 fn evaluate_stateful (
172159 & self ,
160+ input_schema : & SchemaRef ,
173161 partition_batches : & PartitionBatches ,
174162 window_agg_state : & mut PartitionWindowAggStates ,
175163 ) -> Result < ( ) > {
@@ -178,6 +166,10 @@ impl WindowExpr for StandardWindowExpr {
178166 // create a WindowAggState to clone when `window_agg_state` does not contain the respective
179167 // group, which is faster than potentially creating a new one at every iteration
180168 let new_state = WindowAggState :: new ( out_type) ?;
169+
170+ let frame_bounds_comparators =
171+ self . build_frame_bounds_comparators ( input_schema) ?;
172+
181173 for ( partition_row, partition_batch_state) in partition_batches. iter ( ) {
182174 let window_state =
183175 if let Some ( window_state) = window_agg_state. get_mut ( partition_row) {
@@ -225,7 +217,7 @@ impl WindowExpr for StandardWindowExpr {
225217 . get_or_insert_with ( || {
226218 WindowFrameContext :: new (
227219 Arc :: clone ( & self . window_frame ) ,
228- self . frame_comparators . clone ( ) ,
220+ frame_bounds_comparators . clone ( ) ,
229221 )
230222 } )
231223 . calculate_range (
@@ -283,7 +275,6 @@ impl WindowExpr for StandardWindowExpr {
283275 . map ( |e| e. reverse ( ) )
284276 . collect :: < Vec < _ > > ( ) ,
285277 Arc :: new ( self . window_frame . reverse ( ) ) ,
286- Arc :: clone ( & self . schema ) ,
287278 ) ) as _
288279 } )
289280 }
@@ -301,10 +292,6 @@ impl WindowExpr for StandardWindowExpr {
301292 fn create_window_fn ( & self ) -> Result < WindowFn > {
302293 Ok ( WindowFn :: Builtin ( self . expr . create_evaluator ( ) ?) )
303294 }
304-
305- fn frame_bounds_comparators ( & self ) -> Option < WindowFrameBoundsComparators > {
306- self . frame_comparators . clone ( )
307- }
308295}
309296
310297/// Adds a new ordering expression into existing ordering equivalence class(es) based on
0 commit comments