pub trait AggregateFnVTable:
'static
+ Sized
+ Clone
+ Send
+ Sync {
type Options: 'static + Send + Sync + Clone + Debug + Display + PartialEq + Eq + Hash;
type Partial: 'static + Send;
Show 16 methods
// Required methods
fn id(&self) -> AggregateFnId;
fn return_dtype(
&self,
options: &Self::Options,
input_dtype: &DType,
) -> Option<DType>;
fn partial_dtype(
&self,
options: &Self::Options,
input_dtype: &DType,
) -> Option<DType>;
fn empty_partial(
&self,
args: AggregateArgs<'_, Self::Options>,
) -> VortexResult<Self::Partial>;
fn partial_from_scalar(
&self,
args: AggregateArgs<'_, Self::Options>,
scalar: &Scalar,
) -> VortexResult<Self::Partial>;
fn merge_partials(
&self,
args: AggregateArgs<'_, Self::Options>,
first: Self::Partial,
second: Self::Partial,
) -> VortexResult<Self::Partial>;
fn to_scalar(
&self,
args: AggregateArgs<'_, Self::Options>,
partial: &Self::Partial,
) -> VortexResult<Scalar>;
fn is_saturated(
&self,
args: AggregateArgs<'_, Self::Options>,
partial: &Self::Partial,
) -> bool;
fn accumulate(
&self,
args: AggregateArgs<'_, Self::Options>,
state: &mut Self::Partial,
batch: &Columnar,
ctx: &mut ExecutionCtx,
) -> VortexResult<()>;
fn finalize(
&self,
args: AggregateArgs<'_, Self::Options>,
states: ArrayRef,
) -> VortexResult<ArrayRef>;
fn finalize_scalar(
&self,
args: AggregateArgs<'_, Self::Options>,
partial: &Self::Partial,
) -> VortexResult<Scalar>;
// Provided methods
fn serialize(
&self,
options: &Self::Options,
) -> VortexResult<Option<Vec<u8>>> { ... }
fn deserialize(
&self,
_metadata: &[u8],
_session: &VortexSession,
) -> VortexResult<Self::Options> { ... }
fn can_satisfy(
&self,
options: &Self::Options,
requested: &AggregateFnRef,
) -> AggregateFnSatisfaction { ... }
fn zone_stat_default(&self, _input_dtype: &DType) -> Option<AggregateFnRef> { ... }
fn try_accumulate(
&self,
_args: AggregateArgs<'_, Self::Options>,
_state: &mut Self::Partial,
_batch: &ArrayRef,
_ctx: &mut ExecutionCtx,
) -> VortexResult<bool> { ... }
}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§
Required Methods§
Sourcefn id(&self) -> AggregateFnId
fn id(&self) -> AggregateFnId
Returns the ID of the aggregate function vtable.
Sourcefn return_dtype(
&self,
options: &Self::Options,
input_dtype: &DType,
) -> Option<DType>
fn return_dtype( &self, options: &Self::Options, input_dtype: &DType, ) -> Option<DType>
The return DType of the aggregate.
Returns None if the aggregate function cannot be applied to the input dtype.
Sourcefn partial_dtype(
&self,
options: &Self::Options,
input_dtype: &DType,
) -> Option<DType>
fn partial_dtype( &self, options: &Self::Options, input_dtype: &DType, ) -> Option<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 }).
Returns None if the aggregate function cannot be applied to the input dtype.
Sourcefn empty_partial(
&self,
args: AggregateArgs<'_, Self::Options>,
) -> VortexResult<Self::Partial>
fn empty_partial( &self, args: AggregateArgs<'_, Self::Options>, ) -> VortexResult<Self::Partial>
The partial state of a group with no accumulated values.
The identity of merge_partials.
Sourcefn partial_from_scalar(
&self,
args: AggregateArgs<'_, Self::Options>,
scalar: &Scalar,
) -> VortexResult<Self::Partial>
fn partial_from_scalar( &self, args: AggregateArgs<'_, Self::Options>, scalar: &Scalar, ) -> VortexResult<Self::Partial>
Parse a partial scalar into the typed partial state.
The scalar must have dtype args.partial_dtype; this is the inverse of to_scalar.
Sourcefn merge_partials(
&self,
args: AggregateArgs<'_, Self::Options>,
first: Self::Partial,
second: Self::Partial,
) -> VortexResult<Self::Partial>
fn merge_partials( &self, args: AggregateArgs<'_, Self::Options>, first: Self::Partial, second: Self::Partial, ) -> VortexResult<Self::Partial>
Merge two partial states into one.
first accumulated the input preceding second’s. Order-dependent aggregates (e.g.
first/last or is_sorted) rely on this, so the merge need not be commutative. Merging with
empty_partial on either side is the identity.
Sourcefn to_scalar(
&self,
args: AggregateArgs<'_, Self::Options>,
partial: &Self::Partial,
) -> VortexResult<Scalar>
fn to_scalar( &self, args: AggregateArgs<'_, Self::Options>, partial: &Self::Partial, ) -> VortexResult<Scalar>
Convert the partial state into a partial scalar of dtype args.partial_dtype.
This is the inverse of partial_from_scalar: parsing the returned scalar must
reconstruct an equivalent state.
Sourcefn is_saturated(
&self,
args: AggregateArgs<'_, Self::Options>,
partial: &Self::Partial,
) -> bool
fn is_saturated( &self, args: AggregateArgs<'_, Self::Options>, partial: &Self::Partial, ) -> bool
Is the partial state “saturated”, i.e. has it reached a state where the final result is fully determined.
Sourcefn accumulate(
&self,
args: AggregateArgs<'_, Self::Options>,
state: &mut Self::Partial,
batch: &Columnar,
ctx: &mut ExecutionCtx,
) -> VortexResult<()>
fn accumulate( &self, args: AggregateArgs<'_, Self::Options>, state: &mut Self::Partial, batch: &Columnar, ctx: &mut ExecutionCtx, ) -> VortexResult<()>
Accumulate a new canonical array into the partial state.
Sourcefn finalize(
&self,
args: AggregateArgs<'_, Self::Options>,
states: ArrayRef,
) -> VortexResult<ArrayRef>
fn finalize( &self, args: AggregateArgs<'_, Self::Options>, states: ArrayRef, ) -> VortexResult<ArrayRef>
Finalize an array of partial states into an array of aggregate results.
The states array has dtype args.partial_dtype; the result must have dtype
args.return_dtype.
Sourcefn finalize_scalar(
&self,
args: AggregateArgs<'_, Self::Options>,
partial: &Self::Partial,
) -> VortexResult<Scalar>
fn finalize_scalar( &self, args: AggregateArgs<'_, Self::Options>, partial: &Self::Partial, ) -> VortexResult<Scalar>
Finalize a partial state into an aggregate result of dtype args.return_dtype.
Provided Methods§
Sourcefn serialize(&self, options: &Self::Options) -> VortexResult<Option<Vec<u8>>>
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.
Sourcefn deserialize(
&self,
_metadata: &[u8],
_session: &VortexSession,
) -> VortexResult<Self::Options>
fn deserialize( &self, _metadata: &[u8], _session: &VortexSession, ) -> VortexResult<Self::Options>
Deserialize the options of this aggregate function.
Sourcefn can_satisfy(
&self,
options: &Self::Options,
requested: &AggregateFnRef,
) -> AggregateFnSatisfaction
fn can_satisfy( &self, options: &Self::Options, requested: &AggregateFnRef, ) -> AggregateFnSatisfaction
Return whether this stored aggregate can satisfy requested.
The default implementation only treats exactly equal aggregate functions as satisfying the request. Approximate pruning aggregates can override this to expose looser-but-sound bounds.
Sourcefn zone_stat_default(&self, _input_dtype: &DType) -> Option<AggregateFnRef>
fn zone_stat_default(&self, _input_dtype: &DType) -> Option<AggregateFnRef>
If this aggregate should be computed as a default zone statistic for input_dtype, return
the bound aggregate to store. Default: not a zone-map default.
Sourcefn try_accumulate(
&self,
_args: AggregateArgs<'_, Self::Options>,
_state: &mut Self::Partial,
_batch: &ArrayRef,
_ctx: &mut ExecutionCtx,
) -> VortexResult<bool>
fn try_accumulate( &self, _args: AggregateArgs<'_, Self::Options>, _state: &mut Self::Partial, _batch: &ArrayRef, _ctx: &mut ExecutionCtx, ) -> VortexResult<bool>
Try to accumulate the raw array before decompression.
Returns true if the array was handled, false to fall through to the default kernel
dispatch and canonicalization path. When returning false, the partial state must be
unchanged, since the same batch is then accumulated by the fallback path.
This is useful for aggregates that only depend on array metadata (e.g., validity) rather than the encoded data, avoiding unnecessary decompression.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".