Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
review: exract AggregateBatchFn to a separate type
  • Loading branch information
2010YOUY01 committed Jul 8, 2026
commit 32691af0c8593694f2a051de3fc8aafed5bd9d90
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,11 @@ impl<AggrMode> AggregateHashTable<AggrMode> {
/// Each aggregation mode chooses a different `aggregate_fn` according to its
/// semantics. For example, partial aggregation takes raw inputs, and update them
/// into stored partial states, so [`GroupsAccumulator::update_batch`] is used.
pub(super) fn aggregate_batch_inner<F>(
pub(super) fn aggregate_batch_inner(
&mut self,
batch: &RecordBatch,
mut aggregate_fn: F,
) -> Result<()>
where
F: FnMut(
&mut HashAggregateAccumulator,
&EvaluatedAccumulatorArgs,
&[usize],
usize,
) -> Result<()>,
{
aggregate_fn: AggregateBatchFn,
) -> Result<()> {
let evaluated_batch = self.evaluate_batch(batch)?;
let state = self.state.building_mut();

Expand Down Expand Up @@ -341,6 +333,22 @@ pub(super) struct HashAggregateAccumulator {

pub(super) type AggregateAccumulator = HashAggregateAccumulator;

/// Function used by [`AggregateHashTable::aggregate_batch_inner`] to update one
/// accumulator with one evaluated input batch.
///
/// Arguments:
/// * accumulator to update.
/// * accumulator's evaluated arguments and optional filter.
/// * one group index per input row, mapping each row to its interned group.
/// * total number of groups currently interned in that buffer, including newly
/// interned groups.
pub(super) type AggregateBatchFn = fn(
&mut AggregateAccumulator,
&EvaluatedAccumulatorArgs,
&[usize],
usize,
) -> Result<()>;

/// Evaluated aggregate arguments and filter for one input batch.
///
/// For example, `AVG(x + 1) FILTER (WHERE x > 0)` evaluates both `x + 1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use datafusion_common::Result;

use crate::aggregates::AggregateExec;

use super::common::{AggregateHashTable, FinalMarker};
use super::common::{AggregateHashTable, FinalMarker, HashAggregateAccumulator};

/// Implementation specific to final aggregation, where the table stores partial
/// aggregate states and the input rows are also partial states.
Expand Down Expand Up @@ -67,12 +67,7 @@ impl AggregateHashTable<FinalMarker> {
&mut self,
batch: &RecordBatch,
) -> Result<()> {
self.aggregate_batch_inner(
batch,
|acc, values, group_indices, total_num_groups| {
acc.merge_batch(values, group_indices, total_num_groups)
},
)
self.aggregate_batch_inner(batch, HashAggregateAccumulator::merge_batch)
}

pub(in crate::aggregates) fn start_output(&mut self) -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use datafusion_common::Result;

use crate::aggregates::AggregateExec;

use super::common::{AggregateHashTable, PartialReduceMarker};
use super::common::{AggregateHashTable, HashAggregateAccumulator, PartialReduceMarker};

/// Methods specific to the aggregate hash table used in the partial-reduce stage.
impl AggregateHashTable<PartialReduceMarker> {
Expand Down Expand Up @@ -61,12 +61,7 @@ impl AggregateHashTable<PartialReduceMarker> {
&mut self,
batch: &RecordBatch,
) -> Result<()> {
self.aggregate_batch_inner(
batch,
|acc, values, group_indices, total_num_groups| {
acc.merge_batch(values, group_indices, total_num_groups)
},
)
self.aggregate_batch_inner(batch, HashAggregateAccumulator::merge_batch)
}

pub(in crate::aggregates) fn start_output(&mut self) -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,7 @@ impl AggregateHashTable<PartialMarker> {
&mut self,
batch: &RecordBatch,
) -> Result<()> {
self.aggregate_batch_inner(
batch,
|acc, values, group_indices, total_num_groups| {
acc.update_batch(values, group_indices, total_num_groups)
},
)
self.aggregate_batch_inner(batch, HashAggregateAccumulator::update_batch)
}

pub(in crate::aggregates) fn start_output(&mut self) -> Result<()> {
Expand Down