pub trait Aggregate<A, T>{
// Required methods
fn init(&self, ctx: &mut Context<'_>) -> Result<A>;
fn step(&self, ctx: &mut Context<'_>, acc: &mut A) -> Result<()>;
fn finalize(&self, ctx: &mut Context<'_>, acc: Option<A>) -> Result<T>;
}
functions
only.Expand description
Aggregate is the callback interface for user-defined aggregate function.
A
is the type of the aggregation context and T
is the type of the final
result. Implementations should be stateless.
Required Methods§
sourcefn init(&self, ctx: &mut Context<'_>) -> Result<A>
fn init(&self, ctx: &mut Context<'_>) -> Result<A>
Initializes the aggregation context. Will be called prior to the first
call to step()
to set up the context for an
invocation of the function. (Note: init()
will not be called if
there are no rows.)
sourcefn step(&self, ctx: &mut Context<'_>, acc: &mut A) -> Result<()>
fn step(&self, ctx: &mut Context<'_>, acc: &mut A) -> Result<()>
“step” function called once for each row in an aggregate group. May be called 0 times if there are no rows.
sourcefn finalize(&self, ctx: &mut Context<'_>, acc: Option<A>) -> Result<T>
fn finalize(&self, ctx: &mut Context<'_>, acc: Option<A>) -> Result<T>
Computes and returns the final result. Will be called exactly once for
each invocation of the function. If step()
was
called at least once, will be given Some(A)
(the same A
as was
created by init
and given to
step
); if step()
was not
called (because the function is running against 0 rows), will be
given None
.
The passed context will have no arguments.