Skip to main content

AggregateFnVTable

Trait AggregateFnVTable 

Source
pub trait AggregateFnVTable:
    'static
    + Sized
    + Clone
    + Send
    + Sync {
    type Options: 'static + Send + Sync + Clone + Debug + Display + PartialEq + Eq + Hash;
    type Partial: 'static + Send;

    // Required methods
    fn id(&self) -> AggregateFnId;
    fn return_dtype(
        &self,
        options: &Self::Options,
        input_dtype: &DType,
    ) -> VortexResult<DType>;
    fn partial_dtype(
        &self,
        options: &Self::Options,
        input_dtype: &DType,
    ) -> VortexResult<DType>;
    fn empty_partial(
        &self,
        options: &Self::Options,
        input_dtype: &DType,
    ) -> VortexResult<Self::Partial>;
    fn combine_partials(
        &self,
        partial: &mut Self::Partial,
        other: Scalar,
    ) -> VortexResult<()>;
    fn flush(&self, partial: &mut Self::Partial) -> VortexResult<Scalar>;
    fn is_saturated(&self, state: &Self::Partial) -> bool;
    fn accumulate(
        &self,
        state: &mut Self::Partial,
        batch: &Canonical,
        ctx: &mut ExecutionCtx,
    ) -> VortexResult<()>;
    fn finalize(&self, states: ArrayRef) -> VortexResult<ArrayRef>;

    // Provided methods
    fn serialize(
        &self,
        options: &Self::Options,
    ) -> VortexResult<Option<Vec<u8>>> { ... }
    fn deserialize(
        &self,
        _metadata: &[u8],
        _session: &VortexSession,
    ) -> VortexResult<Self::Options> { ... }
    fn finalize_scalar(&self, state: Scalar) -> VortexResult<Scalar> { ... }
}
Expand description

Defines the interface for aggregate function vtables.

This trait is non-object-safe and allows the implementer to make use of associated types for improved type safety, while allowing Vortex to enforce runtime checks on the inputs and outputs of each function.

The AggregateFnVTable trait should be implemented for a struct that holds global data across all instances of the aggregate. In almost all cases, this struct will be an empty unit struct, since most aggregates do not require any global state.

Required Associated Types§

Source

type Options: 'static + Send + Sync + Clone + Debug + Display + PartialEq + Eq + Hash

Options for this aggregate function.

Source

type Partial: 'static + Send

The partial accumulator state for a single group.

Required Methods§

Source

fn id(&self) -> AggregateFnId

Returns the ID of the aggregate function vtable.

Source

fn return_dtype( &self, options: &Self::Options, input_dtype: &DType, ) -> VortexResult<DType>

The return DType of the aggregate.

Source

fn partial_dtype( &self, options: &Self::Options, input_dtype: &DType, ) -> VortexResult<DType>

DType of the intermediate partial accumulator state.

Use a struct dtype when multiple fields are needed (e.g., Mean: Struct { sum: f64, count: u64 }).

Source

fn empty_partial( &self, options: &Self::Options, input_dtype: &DType, ) -> VortexResult<Self::Partial>

Return the partial accumulator state for an empty group.

Source

fn combine_partials( &self, partial: &mut Self::Partial, other: Scalar, ) -> VortexResult<()>

Combine partial scalar state into the accumulator.

Source

fn flush(&self, partial: &mut Self::Partial) -> VortexResult<Scalar>

Flush the partial aggregate for the given accumulator state.

The returned scalar must have the same DType as specified by state_dtype for the options and input dtype used to construct the state.

The internal state of the accumulator is reset to the empty state after flushing.

Source

fn is_saturated(&self, state: &Self::Partial) -> bool

Is the partial accumulator state is “saturated”, i.e. has it reached a state where the final result is fully determined.

Source

fn accumulate( &self, state: &mut Self::Partial, batch: &Canonical, ctx: &mut ExecutionCtx, ) -> VortexResult<()>

Accumulate a new canonical array into the accumulator state.

Source

fn finalize(&self, states: ArrayRef) -> VortexResult<ArrayRef>

Finalize an array of accumulator states into an array of aggregate results.

The provides states array has dtype as specified by state_dtype, the result array must have dtype as specified by return_dtype.

Provided Methods§

Source

fn serialize(&self, options: &Self::Options) -> VortexResult<Option<Vec<u8>>>

Serialize the options for this aggregate function.

Should return Ok(None) if the function is not serializable, and Ok(vec![]) if it is serializable but has no metadata.

Source

fn deserialize( &self, _metadata: &[u8], _session: &VortexSession, ) -> VortexResult<Self::Options>

Deserialize the options of this aggregate function.

Source

fn finalize_scalar(&self, state: Scalar) -> VortexResult<Scalar>

Finalize a scalar accumulator state into an aggregate result.

The provided state has dtype as specified by state_dtype, the result scalar must have dtype as specified by return_dtype.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§