kernel/config/
aggregate.rs1use std::hash::{Hash, Hasher};
2
3use serde::{Deserialize, Serialize};
4
5use crate::common;
6
7use super::{AggregateKey, Filter, FlussoType};
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct Aggregate {
14 pub table: common::TableName,
15 pub op: AggregateOp,
16 pub key: AggregateKey,
17 #[serde(default, skip_serializing_if = "Option::is_none")]
21 pub value_type: Option<FlussoType>,
22 #[serde(default, skip_serializing_if = "Option::is_none")]
23 pub filters: Option<Vec<Filter>>,
24 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
27 pub distinct: bool,
28}
29
30impl Hash for Aggregate {
33 fn hash<H: Hasher>(&self, state: &mut H) {
34 let Self {
35 table,
36 op,
37 key,
38 value_type,
39 filters,
40 distinct,
41 } = self;
42 table.hash(state);
43 op.hash(state);
44 key.hash(state);
45 value_type.hash(state);
46 filters.hash(state);
47 if *distinct {
48 distinct.hash(state);
49 }
50 }
51}
52
53#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
54#[serde(rename_all = "snake_case")]
55pub enum AggregateOp {
56 Count,
57 Sum(common::ColumnName),
58 Avg(common::ColumnName),
59 Min(common::ColumnName),
60 Max(common::ColumnName),
61 Ids {
65 element_type: FlussoType,
66 },
67}