@@ -403,24 +403,26 @@ impl AggregateFunctionExpr {
403
403
Cow :: Borrowed ( & self . schema )
404
404
}
405
405
}
406
-
407
- /// the accumulator used to accumulate values from the expressions.
408
- /// the accumulator expects the same number of arguments as `expressions` and must
409
- /// return states with the same description as `state_fields`
410
- // TODO: factor AccumulatorArgs construction into a private helper to avoid duplication
411
- pub fn create_accumulator ( & self ) -> Result < Box < dyn Accumulator > > {
412
- let schema = self . args_schema ( ) ;
413
- let acc_args = AccumulatorArgs {
406
+ /// Construct AccumulatorArgs for this aggregate using a given schema slice.
407
+ fn make_acc_args ( & self , schema : & Schema ) -> AccumulatorArgs < ' _ > {
408
+ AccumulatorArgs {
414
409
return_field : Arc :: clone ( & self . return_field ) ,
415
- schema : schema . as_ref ( ) ,
410
+ schema,
416
411
ignore_nulls : self . ignore_nulls ,
417
412
order_bys : self . order_bys . as_ref ( ) ,
418
413
is_distinct : self . is_distinct ,
419
414
name : & self . name ,
420
415
is_reversed : self . is_reversed ,
421
416
exprs : & self . args ,
422
- } ;
417
+ }
418
+ }
423
419
420
+ /// the accumulator used to accumulate values from the expressions.
421
+ /// the accumulator expects the same number of arguments as `expressions` and must
422
+ /// return states with the same description as `state_fields`
423
+ pub fn create_accumulator ( & self ) -> Result < Box < dyn Accumulator > > {
424
+ let schema = self . args_schema ( ) ;
425
+ let acc_args = self . make_acc_args ( schema. as_ref ( ) ) ;
424
426
self . fun . accumulator ( acc_args)
425
427
}
426
428
@@ -495,17 +497,7 @@ impl AggregateFunctionExpr {
495
497
/// Creates accumulator implementation that supports retract
496
498
pub fn create_sliding_accumulator ( & self ) -> Result < Box < dyn Accumulator > > {
497
499
let schema = self . args_schema ( ) ;
498
- let args = AccumulatorArgs {
499
- return_field : Arc :: clone ( & self . return_field ) ,
500
- schema : schema. as_ref ( ) ,
501
- ignore_nulls : self . ignore_nulls ,
502
- order_bys : self . order_bys . as_ref ( ) ,
503
- is_distinct : self . is_distinct ,
504
- name : & self . name ,
505
- is_reversed : self . is_reversed ,
506
- exprs : & self . args ,
507
- } ;
508
-
500
+ let args = self . make_acc_args ( schema. as_ref ( ) ) ;
509
501
let accumulator = self . fun . create_sliding_accumulator ( args) ?;
510
502
511
503
// Accumulators that have window frame startings different
@@ -565,16 +557,7 @@ impl AggregateFunctionExpr {
565
557
/// `[Self::create_groups_accumulator`] will be called.
566
558
pub fn groups_accumulator_supported ( & self ) -> bool {
567
559
let schema = self . args_schema ( ) ;
568
- let args = AccumulatorArgs {
569
- return_field : Arc :: clone ( & self . return_field ) ,
570
- schema : schema. as_ref ( ) ,
571
- ignore_nulls : self . ignore_nulls ,
572
- order_bys : self . order_bys . as_ref ( ) ,
573
- is_distinct : self . is_distinct ,
574
- name : & self . name ,
575
- is_reversed : self . is_reversed ,
576
- exprs : & self . args ,
577
- } ;
560
+ let args = self . make_acc_args ( schema. as_ref ( ) ) ;
578
561
self . fun . groups_accumulator_supported ( args)
579
562
}
580
563
@@ -585,16 +568,7 @@ impl AggregateFunctionExpr {
585
568
/// implemented in addition to [`Accumulator`].
586
569
pub fn create_groups_accumulator ( & self ) -> Result < Box < dyn GroupsAccumulator > > {
587
570
let schema = self . args_schema ( ) ;
588
- let args = AccumulatorArgs {
589
- return_field : Arc :: clone ( & self . return_field ) ,
590
- schema : schema. as_ref ( ) ,
591
- ignore_nulls : self . ignore_nulls ,
592
- order_bys : self . order_bys . as_ref ( ) ,
593
- is_distinct : self . is_distinct ,
594
- name : & self . name ,
595
- is_reversed : self . is_reversed ,
596
- exprs : & self . args ,
597
- } ;
571
+ let args = self . make_acc_args ( schema. as_ref ( ) ) ;
598
572
self . fun . create_groups_accumulator ( args)
599
573
}
600
574
0 commit comments