pub trait RowAccumulator: Send + Sync + Debug {
fn update_batch(
&mut self,
values: &[ArrayRef],
accessor: &mut RowAccessor<'_>
) -> Result<()>;
fn merge_batch(
&mut self,
states: &[ArrayRef],
accessor: &mut RowAccessor<'_>
) -> Result<()>;
fn evaluate(&self, accessor: &RowAccessor<'_>) -> Result<ScalarValue>;
fn state_index(&self) -> usize;
}
Expand description
Row-based accumulator where the internal aggregate state(s) are stored using row format.
Unlike the datafusion_expr::Accumulator
, the RowAccumulator
does not store the state internally.
Instead, it knows how to access/update the state stored in a row via the the provided accessor and
its state’s starting field index in the row.
For example, we are evaluating SELECT a, sum(b), avg(c), count(d) from GROUP BY a;
, we would have one row used as
aggregation state for each distinct a
value, the index of the first and the only state of sum(b)
would be 0,
the index of the first state of avg(c)
would be 1, and the index of the first and only state of cound(d)
would be 3:
sum(b) state_index = 0 count(d) state_index = 3 | | v v +––––+–––––+––––+–––––+ | sum(b) | count(c) | sum(c) | count(d) | +––––+–––––+––––+–––––+ ^ | avg(c) state_index = 1
Required Methods
fn update_batch(
&mut self,
values: &[ArrayRef],
accessor: &mut RowAccessor<'_>
) -> Result<()>
fn update_batch(
&mut self,
values: &[ArrayRef],
accessor: &mut RowAccessor<'_>
) -> Result<()>
updates the accumulator’s state from a vector of arrays.
fn merge_batch(
&mut self,
states: &[ArrayRef],
accessor: &mut RowAccessor<'_>
) -> Result<()>
fn merge_batch(
&mut self,
states: &[ArrayRef],
accessor: &mut RowAccessor<'_>
) -> Result<()>
updates the accumulator’s state from a vector of states.
fn evaluate(&self, accessor: &RowAccessor<'_>) -> Result<ScalarValue>
fn evaluate(&self, accessor: &RowAccessor<'_>) -> Result<ScalarValue>
returns its value based on its current state.
fn state_index(&self) -> usize
fn state_index(&self) -> usize
State’s starting field index in the row.