Skip to main content

VAggregate

Trait VAggregate 

Source
pub trait VAggregate: Sized {
    type State: Send + Sync + 'static;
    type Shared: Send + Sync + 'static;

    // Required methods
    fn parameters() -> Result<Vec<LogicalType>>;
    fn return_type() -> Result<LogicalType>;
    fn init() -> Self::State;
    fn update(
        shared: &Self::Shared,
        state: &mut Self::State,
        input: &DataChunkHandle,
        row: usize,
    ) -> UdfResult<()>;
    fn combine(
        shared: &Self::Shared,
        source: &Self::State,
        target: &mut Self::State,
    );
    fn finalize(
        shared: &Self::Shared,
        state: &Self::State,
        output: &mut VectorMut<'_>,
        row: usize,
    ) -> UdfResult<()>;

    // Provided method
    fn special_handling() -> bool { ... }
}
Expand description

A DuckDB aggregate function: folds a set of input rows into one result value.

See the callback-containment contract in crate::udf.

Required Associated Types§

Source

type State: Send + Sync + 'static

The per-group accumulator. Allocated by DuckDB (uninitialised), set up by init, and dropped by the generated destructor.

Source

type Shared: Send + Sync + 'static

Registration-time shared state, available read-only to every callback via DuckDB’s extra-info slot. Use () if the aggregate needs none.

Required Methods§

Source

fn parameters() -> Result<Vec<LogicalType>>

The input parameter types (one overload).

§Errors

Returns an error if a parameter’s logical type cannot be built.

Source

fn return_type() -> Result<LogicalType>

The result type produced by finalize.

§Errors

Returns an error if the return type cannot be built.

Source

fn init() -> Self::State

The initial accumulator value for a fresh group.

Source

fn update( shared: &Self::Shared, state: &mut Self::State, input: &DataChunkHandle, row: usize, ) -> UdfResult<()>

Folds input’s row row into state. shared is the registration state.

§Errors

Returns an error to fail the query with that message.

Source

fn combine( shared: &Self::Shared, source: &Self::State, target: &mut Self::State, )

Merges source into target (parallel/partial aggregation).

Source

fn finalize( shared: &Self::Shared, state: &Self::State, output: &mut VectorMut<'_>, row: usize, ) -> UdfResult<()>

Writes the finalised value of state into output at row.

§Errors

Returns an error to fail the query with that message.

Provided Methods§

Source

fn special_handling() -> bool

Whether the aggregate should still be invoked for NULL inputs. false by default (DuckDB skips rows whose argument is NULL).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§