use crate::storage::schema::Value;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AggregateOp {
CountStar,
CountColumn,
Sum,
Avg,
Min,
Max,
}
#[derive(Debug, Clone)]
pub struct AggregateExpr {
pub op: AggregateOp,
pub input_index: usize,
pub output_name: String,
}
#[derive(Debug, Clone)]
pub struct AggregateQueryAst {
pub group_by_output_name: String,
pub aggregates: Vec<AggregateExpr>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PlanError {
NoAggregates,
DuplicateOutputName(String),
InputIndexOutOfRange { aggregate: String, index: usize },
}
impl std::fmt::Display for PlanError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PlanError::NoAggregates => write!(f, "aggregate plan has no aggregates"),
PlanError::DuplicateOutputName(n) => write!(f, "duplicate aggregate output name: {n}"),
PlanError::InputIndexOutOfRange { aggregate, index } => write!(
f,
"aggregate `{aggregate}` references input slot {index} which the scan does not expose",
),
}
}
}
impl std::error::Error for PlanError {}
pub type AggregateValue = Value;