@@ -210,17 +210,14 @@ impl<AggrMode> AggregateHashTable<AggrMode> {
210210 ///
211211 /// Each aggregation mode chooses a different `materialize_accumulator_fn`
212212 /// according to its semantics. For example, partial aggregation emits
213- /// partial states to feed the final stage, so it us [`GroupsAccumulator::state`].
213+ /// partial states to feed the final stage, so it uses [`GroupsAccumulator::state`].
214214 ///
215215 /// This is a temporary solution until blocked state management is implemented:
216216 /// Issue: <https://github.com/apache/datafusion/issues/7065>
217- pub ( super ) fn next_output_batch_inner < F > (
217+ pub ( super ) fn next_output_batch_inner (
218218 & mut self ,
219- mut materialize_accumulator_fn : F ,
220- ) -> Result < Option < RecordBatch > >
221- where
222- F : FnMut ( & mut HashAggregateAccumulator , EmitTo , & mut Vec < ArrayRef > ) -> Result < ( ) > ,
223- {
219+ materialize_accumulator_fn : MaterializeAccumulatorFn ,
220+ ) -> Result < Option < RecordBatch > > {
224221 let output_schema = Arc :: clone ( & self . output_schema ) ;
225222 let batch_size = self . batch_size ;
226223
@@ -237,7 +234,7 @@ impl<AggrMode> AggregateHashTable<AggrMode> {
237234 let timer = self . group_by_metrics . emitting_time . timer ( ) ;
238235 let mut columns = state. group_values . emit ( emit_to) ?;
239236 for acc in state. accumulators . iter_mut ( ) {
240- materialize_accumulator_fn ( acc, emit_to, & mut columns ) ? ;
237+ columns . extend ( materialize_accumulator_fn ( acc, emit_to) ? ) ;
241238 }
242239 drop ( timer) ;
243240
@@ -349,6 +346,15 @@ pub(super) type AggregateBatchFn = fn(
349346 usize ,
350347) -> Result < ( ) > ;
351348
349+ /// Function used by [`AggregateHashTable::next_output_batch_inner`] to
350+ /// materialize one accumulator's output columns.
351+ ///
352+ /// Arguments:
353+ /// * accumulator to materialize.
354+ /// * group range to emit from the accumulator.
355+ pub ( super ) type MaterializeAccumulatorFn =
356+ fn ( & mut AggregateAccumulator , EmitTo ) -> Result < Vec < ArrayRef > > ;
357+
352358/// Evaluated aggregate arguments and filter for one input batch.
353359///
354360/// For example, `AVG(x + 1) FILTER (WHERE x > 0)` evaluates both `x + 1`
@@ -547,6 +553,13 @@ impl HashAggregateAccumulator {
547553 self . accumulator . evaluate ( emit_to)
548554 }
549555
556+ pub ( super ) fn evaluate_to_columns (
557+ & mut self ,
558+ emit_to : EmitTo ,
559+ ) -> Result < Vec < ArrayRef > > {
560+ Ok ( vec ! [ self . evaluate( emit_to) ?] )
561+ }
562+
550563 /// Evaluating partial aggregate results according to `EmitTo`, and reset inner
551564 /// states. (e.g. after `state(EmitTo::All)`, it returns all accumulated groups
552565 /// , and clear the inner buffers)
0 commit comments