pub trait AggregateFunction: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn metadata(&self) -> FunctionMetadata;
fn argument_specs(&self) -> Vec<ArgSpec>;
fn on_bind(&self, params: &AggregateBindParams) -> Result<BindResponse>;
fn initial_state(&self) -> Vec<u8> ⓘ;
fn update(
&self,
states: &mut HashMap<i64, Vec<u8>>,
group_ids: &Int64Array,
columns: &[ArrayRef],
) -> Result<()>;
fn combine(&self, target: Vec<u8>, source: Vec<u8>) -> Result<Vec<u8>>;
fn finalize(
&self,
output_schema: &SchemaRef,
group_ids: &Int64Array,
states: &[Option<Vec<u8>>],
) -> Result<RecordBatch>;
// Provided methods
fn window(
&self,
_partition: &RecordBatch,
_output_schema: &SchemaRef,
_frames: &[Vec<(i64, i64)>],
_filter_mask: Option<&[bool]>,
) -> Result<ArrayRef> { ... }
fn streaming_chunk(
&self,
_chunk: &RecordBatch,
_partition_key_count: usize,
_order_key_count: usize,
_states: &mut HashMap<Vec<u8>, Vec<u8>>,
) -> Result<ArrayRef> { ... }
fn finalize_with_args(
&self,
output_schema: &SchemaRef,
group_ids: &Int64Array,
states: &[Option<Vec<u8>>],
_args: &Arguments,
) -> Result<RecordBatch> { ... }
}Expand description
An aggregate VGI function.
Required Methods§
fn name(&self) -> &str
fn metadata(&self) -> FunctionMetadata
fn argument_specs(&self) -> Vec<ArgSpec>
Sourcefn on_bind(&self, params: &AggregateBindParams) -> Result<BindResponse>
fn on_bind(&self, params: &AggregateBindParams) -> Result<BindResponse>
Resolve the (single-column result) output schema.
Sourcefn initial_state(&self) -> Vec<u8> ⓘ
fn initial_state(&self) -> Vec<u8> ⓘ
The serialized initial state for a fresh group.
Sourcefn update(
&self,
states: &mut HashMap<i64, Vec<u8>>,
group_ids: &Int64Array,
columns: &[ArrayRef],
) -> Result<()>
fn update( &self, states: &mut HashMap<i64, Vec<u8>>, group_ids: &Int64Array, columns: &[ArrayRef], ) -> Result<()>
Fold the batch’s rows into the per-group states map. states is
pre-loaded (initial state for new groups) for every group id present in
group_ids. columns are the input columns with the group-id column
already stripped.
Sourcefn combine(&self, target: Vec<u8>, source: Vec<u8>) -> Result<Vec<u8>>
fn combine(&self, target: Vec<u8>, source: Vec<u8>) -> Result<Vec<u8>>
Merge source state into target state, returning the new target.
Sourcefn finalize(
&self,
output_schema: &SchemaRef,
group_ids: &Int64Array,
states: &[Option<Vec<u8>>],
) -> Result<RecordBatch>
fn finalize( &self, output_schema: &SchemaRef, group_ids: &Int64Array, states: &[Option<Vec<u8>>], ) -> Result<RecordBatch>
Build the single-column output batch: one row per group_ids entry.
states[i] is the loaded state for group_ids[i] (None if unseen).
Provided Methods§
Sourcefn window(
&self,
_partition: &RecordBatch,
_output_schema: &SchemaRef,
_frames: &[Vec<(i64, i64)>],
_filter_mask: Option<&[bool]>,
) -> Result<ArrayRef>
fn window( &self, _partition: &RecordBatch, _output_schema: &SchemaRef, _frames: &[Vec<(i64, i64)>], _filter_mask: Option<&[bool]>, ) -> Result<ArrayRef>
Evaluate the windowed aggregate for each output row. frames[i] is the
list of (begin, end) sub-frames for output row i over the
partition’s input columns; returns the output column (one element per
row), matching output_schema. Only supports_window functions
override this; the default errors.
Sourcefn streaming_chunk(
&self,
_chunk: &RecordBatch,
_partition_key_count: usize,
_order_key_count: usize,
_states: &mut HashMap<Vec<u8>, Vec<u8>>,
) -> Result<ArrayRef>
fn streaming_chunk( &self, _chunk: &RecordBatch, _partition_key_count: usize, _order_key_count: usize, _states: &mut HashMap<Vec<u8>, Vec<u8>>, ) -> Result<ArrayRef>
Process one chunk of a streaming-partitioned session. The chunk’s
columns are [partition_key_cols.., order_key_cols.., value_cols..].
states is the cross-chunk per-partition state map (partition-key bytes
→ opaque state bytes), loaded and persisted by the framework. Returns a
same-length output column. Only streaming_partitioned functions
override this; the default errors.
Sourcefn finalize_with_args(
&self,
output_schema: &SchemaRef,
group_ids: &Int64Array,
states: &[Option<Vec<u8>>],
_args: &Arguments,
) -> Result<RecordBatch>
fn finalize_with_args( &self, output_schema: &SchemaRef, group_ids: &Int64Array, states: &[Option<Vec<u8>>], _args: &Arguments, ) -> Result<RecordBatch>
Like Self::finalize, but with access to the bind-time arguments (stashed
at aggregate_bind, reloaded here). Override for ConstParam(phase= "finalize") aggregates like vgi_percentile. The default ignores them.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".