use std::hash::{Hash, Hasher};
use serde::{Deserialize, Serialize};
use crate::common;
use super::{AggregateKey, Filter, FlussoType};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Aggregate {
pub table: common::TableName,
pub op: AggregateOp,
pub key: AggregateKey,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub value_type: Option<FlussoType>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub filters: Option<Vec<Filter>>,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub distinct: bool,
}
impl Hash for Aggregate {
fn hash<H: Hasher>(&self, state: &mut H) {
let Self {
table,
op,
key,
value_type,
filters,
distinct,
} = self;
table.hash(state);
op.hash(state);
key.hash(state);
value_type.hash(state);
filters.hash(state);
if *distinct {
distinct.hash(state);
}
}
}
#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum AggregateOp {
Count,
Sum(common::ColumnName),
Avg(common::ColumnName),
Min(common::ColumnName),
Max(common::ColumnName),
Ids {
element_type: FlussoType,
},
}