@@ -171,9 +171,11 @@ impl AggregateUDF {
171
171
self . inner . accumulator ( acc_args)
172
172
}
173
173
174
- /// Return the fields of the intermediate state used by this aggregator, given
175
- /// its state name, value type and ordering fields. See [`AggregateUDFImpl::state_fields`]
176
- /// for more details. Supports multi-phase aggregations
174
+ /// Return the fields used to store the intermediate state for this aggregator, given
175
+ /// the name of the aggregate, value type and ordering fields. See [`AggregateUDFImpl::state_fields`]
176
+ /// for more details.
177
+ ///
178
+ /// This is used to support multi-phase aggregations
177
179
pub fn state_fields (
178
180
& self ,
179
181
name : & str ,
@@ -283,13 +285,28 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
283
285
/// `acc_args`: the arguments to the accumulator. See [`AccumulatorArgs`] for more details.
284
286
fn accumulator ( & self , acc_args : AccumulatorArgs ) -> Result < Box < dyn Accumulator > > ;
285
287
286
- /// Return the fields of the intermediate state.
288
+ /// Return the fields used to store the intermediate state of this accumulator.
289
+ ///
290
+ /// # Arguments:
291
+ /// 1. `name`: the name of the expression (e.g. AVG, SUM, etc)
292
+ /// 2. `value_type`: Aggregate's aggregate's output (returned by [`Self::return_type`])
293
+ /// 3. `ordering_fields`: the fields used to order the input arguments, if any.
294
+ /// Empty if no ordering expression is provided.
295
+ ///
296
+ /// # Notes:
287
297
///
288
- /// name: the name of the state
298
+ /// The default implementation returns a single state field named `name`
299
+ /// with the same type as `value_type`. This is suitable for aggregates such
300
+ /// as `SUM` or `MIN` where partial state can be combined by applying the
301
+ /// same aggregate.
289
302
///
290
- /// value_type: the type of the value, it should be the result of the `return_type`
303
+ /// For aggregates such as `AVG` where the partial state is more complex
304
+ /// (e.g. a COUNT and a SUM), this method is used to define the additional
305
+ /// fields.
291
306
///
292
- /// ordering_fields: the fields used for ordering, empty if no ordering expression is provided
307
+ /// The name of the fields must be unique within the query and thus should
308
+ /// be derived from `name`. See [`format_state_name`] for a utility function
309
+ /// to generate a unique name.
293
310
fn state_fields (
294
311
& self ,
295
312
name : & str ,
0 commit comments