Skip to main content

Accumulator

Struct Accumulator 

Source
pub struct Accumulator { /* private fields */ }
Expand description

A running aggregate.

Implementations§

Source§

impl Accumulator

Source

pub fn new(name: &str, returns: &LogicalType) -> Result<Self>

A fresh accumulator for a named aggregate returning returns.

§Errors

If the name is not an aggregate this crate implements.

Source

pub fn update(&mut self, args: &[Value]) -> Result<()>

Folds one row in.

§Errors

If the argument count is wrong for the aggregate, if the value is not one the aggregate can accumulate, or if a whole running total overflows.

Source

pub fn update_run(&mut self, args: &[Vector], rows: usize) -> Result<()>

Folds a whole vector in, in one pass over the data and without building a Value per row.

rows is how many rows to fold, which is the row count of the chunk rather than the capacity of the vectors in it. count(*) takes no argument and reads nothing but that number, and every other aggregate here takes exactly one vector.

A shape the one pass form does not cover falls through to Accumulator::update per row and records itself in crate::fallback, so this always reaches the answer the row at a time loop reaches and never a different one. That is not a slogan about floating point: the running total below is carried into the vector loop rather than restarted at zero, precisely so that the additions happen in the same order and round the same way.

§Errors

The same errors Accumulator::update raises, for the same reasons.

Source

pub fn finish(&self) -> Result<Value>

The aggregate’s answer.

§Errors

If the running total does not fit the declared return type.

Trait Implementations§

Source§

impl Clone for Accumulator

Source§

fn clone(&self) -> Accumulator

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Accumulator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.