@@ -19,8 +19,8 @@ use crate::ArrayRef;
1919use crate :: Columnar ;
2020use crate :: ExecutionCtx ;
2121use crate :: aggregate_fn:: Accumulator ;
22+ use crate :: aggregate_fn:: AggregateArgs ;
2223use crate :: aggregate_fn:: AggregateDTypes ;
23- use crate :: aggregate_fn:: AggregateDTypesRef ;
2424use crate :: aggregate_fn:: AggregateFnId ;
2525use crate :: aggregate_fn:: AggregateFnVTable ;
2626use crate :: aggregate_fn:: DynAccumulator ;
@@ -87,21 +87,19 @@ pub trait BinaryCombined: 'static + Send + Sync + Clone {
8787
8888 /// Combine the finalized left and right results into the final aggregate.
8989 ///
90- /// `dtypes ` describes the combined aggregate; `left` and `right` already have their child's
91- /// result dtype. The returned array must have dtype `dtypes .return_dtype`.
90+ /// `args ` describes the combined aggregate; `left` and `right` already have their child's
91+ /// result dtype. The returned array must have dtype `args .return_dtype`.
9292 fn finalize (
9393 & self ,
94- options : & CombinedOptions < Self > ,
95- dtypes : AggregateDTypesRef < ' _ > ,
94+ args : AggregateArgs < ' _ , CombinedOptions < Self > > ,
9695 left : ArrayRef ,
9796 right : ArrayRef ,
9897 ) -> VortexResult < ArrayRef > ;
9998
100- /// Combine the finalized child scalars into a result of dtype `dtypes .return_dtype`.
99+ /// Combine the finalized child scalars into a result of dtype `args .return_dtype`.
101100 fn finalize_scalar (
102101 & self ,
103- options : & CombinedOptions < Self > ,
104- dtypes : AggregateDTypesRef < ' _ > ,
102+ args : AggregateArgs < ' _ , CombinedOptions < Self > > ,
105103 left_scalar : Scalar ,
106104 right_scalar : Scalar ,
107105 ) -> VortexResult < Scalar > ;
@@ -153,11 +151,11 @@ impl<T: BinaryCombined> Combined<T> {
153151 /// Construct a pair of empty child accumulators.
154152 fn new_child_accumulators (
155153 & self ,
156- options : & CombinedOptions < T > ,
157- input_dtype : & DType ,
154+ args : AggregateArgs < ' _ , CombinedOptions < T > > ,
158155 ) -> VortexResult < ChildAccumulators < T > > {
159- let left = Accumulator :: try_new ( self . 0 . left ( ) , options. 0 . clone ( ) , input_dtype. clone ( ) ) ?;
160- let right = Accumulator :: try_new ( self . 0 . right ( ) , options. 1 . clone ( ) , input_dtype. clone ( ) ) ?;
156+ let left = Accumulator :: try_new ( self . 0 . left ( ) , args. options . 0 . clone ( ) , args. dtype . clone ( ) ) ?;
157+ let right =
158+ Accumulator :: try_new ( self . 0 . right ( ) , args. options . 1 . clone ( ) , args. dtype . clone ( ) ) ?;
161159 Ok ( ( left, right) )
162160 }
163161}
@@ -191,21 +189,16 @@ impl<T: BinaryCombined> AggregateFnVTable for Combined<T> {
191189 Some ( self . 0 . partial_struct_dtype ( l, r) )
192190 }
193191
194- fn empty_partial (
195- & self ,
196- options : & Self :: Options ,
197- dtypes : AggregateDTypesRef < ' _ > ,
198- ) -> VortexResult < Self :: Partial > {
199- self . new_child_accumulators ( options, dtypes. dtype )
192+ fn empty_partial ( & self , args : AggregateArgs < ' _ , Self :: Options > ) -> VortexResult < Self :: Partial > {
193+ self . new_child_accumulators ( args)
200194 }
201195
202196 fn partial_from_scalar (
203197 & self ,
204- options : & Self :: Options ,
205- dtypes : AggregateDTypesRef < ' _ > ,
198+ args : AggregateArgs < ' _ , Self :: Options > ,
206199 scalar : Scalar ,
207200 ) -> VortexResult < Self :: Partial > {
208- let ( mut left, mut right) = self . new_child_accumulators ( options , dtypes . dtype ) ?;
201+ let ( mut left, mut right) = self . new_child_accumulators ( args ) ?;
209202 // A null partial represents an empty group and parses to empty child accumulators.
210203 if !scalar. is_null ( ) {
211204 let s = scalar. as_struct ( ) ;
@@ -225,8 +218,7 @@ impl<T: BinaryCombined> AggregateFnVTable for Combined<T> {
225218
226219 fn merge_partials (
227220 & self ,
228- _options : & Self :: Options ,
229- _dtypes : AggregateDTypesRef < ' _ > ,
221+ _args : AggregateArgs < ' _ , Self :: Options > ,
230222 ( mut left, mut right) : Self :: Partial ,
231223 ( mut other_left, mut other_right) : Self :: Partial ,
232224 ) -> VortexResult < Self :: Partial > {
@@ -238,22 +230,20 @@ impl<T: BinaryCombined> AggregateFnVTable for Combined<T> {
238230
239231 fn to_scalar (
240232 & self ,
241- _options : & Self :: Options ,
242- dtypes : AggregateDTypesRef < ' _ > ,
233+ args : AggregateArgs < ' _ , Self :: Options > ,
243234 partial : & Self :: Partial ,
244235 ) -> VortexResult < Scalar > {
245236 let l_scalar = partial. 0 . partial_scalar ( ) ?;
246237 let r_scalar = partial. 1 . partial_scalar ( ) ?;
247238 Ok ( Scalar :: struct_ (
248- dtypes . partial_dtype . clone ( ) ,
239+ args . partial_dtype . clone ( ) ,
249240 vec ! [ l_scalar, r_scalar] ,
250241 ) )
251242 }
252243
253244 fn is_saturated (
254245 & self ,
255- _options : & Self :: Options ,
256- _dtypes : AggregateDTypesRef < ' _ > ,
246+ _args : AggregateArgs < ' _ , Self :: Options > ,
257247 partial : & Self :: Partial ,
258248 ) -> bool {
259249 partial. 0 . is_saturated ( ) && partial. 1 . is_saturated ( )
@@ -266,8 +256,7 @@ impl<T: BinaryCombined> AggregateFnVTable for Combined<T> {
266256 /// `true` so [`Self::accumulate`] is unreachable.
267257 fn try_accumulate (
268258 & self ,
269- _options : & Self :: Options ,
270- _dtypes : AggregateDTypesRef < ' _ > ,
259+ _args : AggregateArgs < ' _ , Self :: Options > ,
271260 state : & mut Self :: Partial ,
272261 batch : & ArrayRef ,
273262 ctx : & mut ExecutionCtx ,
@@ -279,8 +268,7 @@ impl<T: BinaryCombined> AggregateFnVTable for Combined<T> {
279268
280269 fn accumulate (
281270 & self ,
282- _options : & Self :: Options ,
283- _dtypes : AggregateDTypesRef < ' _ > ,
271+ _args : AggregateArgs < ' _ , Self :: Options > ,
284272 _state : & mut Self :: Partial ,
285273 _batch : & Columnar ,
286274 _ctx : & mut ExecutionCtx ,
@@ -290,29 +278,27 @@ impl<T: BinaryCombined> AggregateFnVTable for Combined<T> {
290278
291279 fn finalize (
292280 & self ,
293- options : & Self :: Options ,
294- dtypes : AggregateDTypesRef < ' _ > ,
281+ args : AggregateArgs < ' _ , Self :: Options > ,
295282 states : ArrayRef ,
296283 ) -> VortexResult < ArrayRef > {
297284 let l_field = states. get_item ( FieldName :: from ( self . 0 . left_name ( ) ) ) ?;
298285 let r_field = states. get_item ( FieldName :: from ( self . 0 . right_name ( ) ) ) ?;
299286 let left = self . 0 . left ( ) ;
300287 let right = self . 0 . right ( ) ;
301- let l_dtypes = AggregateDTypes :: try_new ( & left, & options. 0 , dtypes . dtype . clone ( ) ) ?;
302- let r_dtypes = AggregateDTypes :: try_new ( & right, & options. 1 , dtypes . dtype . clone ( ) ) ?;
303- let l_finalized = left. finalize ( & options. 0 , l_dtypes . borrow ( ) , l_field) ?;
304- let r_finalized = right. finalize ( & options. 1 , r_dtypes . borrow ( ) , r_field) ?;
305- BinaryCombined :: finalize ( & self . 0 , options , dtypes , l_finalized, r_finalized)
288+ let l_dtypes = AggregateDTypes :: try_new ( & left, & args . options . 0 , args . dtype . clone ( ) ) ?;
289+ let r_dtypes = AggregateDTypes :: try_new ( & right, & args . options . 1 , args . dtype . clone ( ) ) ?;
290+ let l_finalized = left. finalize ( l_dtypes . args ( & args . options . 0 ) , l_field) ?;
291+ let r_finalized = right. finalize ( r_dtypes . args ( & args . options . 1 ) , r_field) ?;
292+ BinaryCombined :: finalize ( & self . 0 , args , l_finalized, r_finalized)
306293 }
307294
308295 fn finalize_scalar (
309296 & self ,
310- options : & Self :: Options ,
311- dtypes : AggregateDTypesRef < ' _ > ,
297+ args : AggregateArgs < ' _ , Self :: Options > ,
312298 partial : & Self :: Partial ,
313299 ) -> VortexResult < Scalar > {
314300 let l_scalar = partial. 0 . final_scalar ( ) ?;
315301 let r_scalar = partial. 1 . final_scalar ( ) ?;
316- BinaryCombined :: finalize_scalar ( & self . 0 , options , dtypes , l_scalar, r_scalar)
302+ BinaryCombined :: finalize_scalar ( & self . 0 , args , l_scalar, r_scalar)
317303 }
318304}
0 commit comments