linkrs_query/executor/streaming/operators/blocking/
aggregate.rs1use std::collections::HashMap;
2
3use crate::executor::streaming::helpers::accumulator_states::{
4 decode_partial_with_args, AggregateAccumulator,
5};
6use crate::executor::streaming::spill::{HashPartitionSpiller, SpilledRun};
7use linkrs_core::columnar::{MaterializedBatch, RowKey};
8use linkrs_core::types::expr::Expression;
9use linkrs_core::types::operators::AggregateFunction;
10use linkrs_core::Value;
11
12pub const ACCUMULATOR_OVERHEAD_BYTES: usize = 64;
17
18#[derive(Debug)]
19pub struct AggregateState {
20 pub group_map: HashMap<RowKey, Vec<AggregateAccumulator>>,
23 pub accumulator_overhead: usize,
25 pub result_batch: MaterializedBatch,
27 pub emitted_offset: usize,
29 pub partition_spiller: Option<HashPartitionSpiller>,
30 pub spilled_runs: Vec<Option<SpilledRun>>,
31 pub current_partition: usize,
32 pub has_spilled: bool,
33 pub output_complete: bool,
35 pub col_names: Vec<String>,
36}
37
38#[derive(Debug)]
39pub struct GroupByState {
40 pub batch: MaterializedBatch,
42 pub col_names: Vec<String>,
43 pub result_batch: MaterializedBatch,
45 pub emitted_offset: usize,
47 pub partition_spiller: Option<HashPartitionSpiller>,
48 pub spilled_runs: Vec<Option<SpilledRun>>,
49 pub current_partition: usize,
50 pub has_spilled: bool,
51 pub output_complete: bool,
53}
54
55#[derive(Debug)]
56pub struct PartialAggregateState {
57 pub group_map: HashMap<RowKey, Vec<AggregateAccumulator>>,
58 pub col_names: Vec<String>,
59 pub result_batch: MaterializedBatch,
61 pub emitted_offset: usize,
63}
64
65#[derive(Debug)]
66pub struct FinalAggregateState {
67 pub group_map: HashMap<RowKey, Vec<AggregateAccumulator>>,
68 pub col_names: Vec<String>,
69 pub result_batch: MaterializedBatch,
71 pub emitted_offset: usize,
73}
74
75pub(crate) fn value_to_partial_accumulator(
76 func: &AggregateFunction,
77 args: &[Expression],
78 value: &Value,
79) -> Option<AggregateAccumulator> {
80 decode_partial_with_args(func, args, value)
81}