add coalesce(), refactor/rename add_label()

This commit is contained in:
jussisaurio 2024-07-13 23:03:25 +03:00
parent 9458522164
commit 851aea212d
5 changed files with 451 additions and 213 deletions

View file

@ -1,3 +1,5 @@
use std::str::FromStr;
#[derive(Debug, Clone, PartialEq)]
pub enum AggFunc {
Avg,
@ -24,3 +26,31 @@ impl AggFunc {
}
}
}
pub enum SingleRowFunc {
Coalesce,
}
pub enum Func {
Agg(AggFunc),
SingleRow(SingleRowFunc),
}
impl FromStr for Func {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"avg" => Ok(Func::Agg(AggFunc::Avg)),
"count" => Ok(Func::Agg(AggFunc::Count)),
"group_concat" => Ok(Func::Agg(AggFunc::GroupConcat)),
"max" => Ok(Func::Agg(AggFunc::Max)),
"min" => Ok(Func::Agg(AggFunc::Min)),
"string_agg" => Ok(Func::Agg(AggFunc::StringAgg)),
"sum" => Ok(Func::Agg(AggFunc::Sum)),
"total" => Ok(Func::Agg(AggFunc::Total)),
"coalesce" => Ok(Func::SingleRow(SingleRowFunc::Coalesce)),
_ => Err(()),
}
}
}