|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
use std::cmp::min;
|
|
|
|
|
use std::cmp::{max, min};
|
|
|
|
|
use std::fmt::{Debug, Formatter};
|
|
|
|
|
|
|
|
|
|
use anyhow::{bail, Result};
|
|
|
|
@ -67,14 +67,11 @@ fn aggr_sum(accum: &DataValue, current: &DataValue) -> Result<DataValue> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
define_aggr!(AGGR_MIN, false);
|
|
|
|
|
define_aggr!(AGGR_MIN, true);
|
|
|
|
|
fn aggr_min(accum: &DataValue, current: &DataValue) -> Result<DataValue> {
|
|
|
|
|
match (accum, current) {
|
|
|
|
|
(DataValue::Bottom, DataValue::Bottom) => Ok(DataValue::Float(f64::infinity().into())),
|
|
|
|
|
(DataValue::Bottom, DataValue::Int(i)) => Ok(DataValue::Int(*i)),
|
|
|
|
|
(DataValue::Bottom, DataValue::Float(f)) => Ok(DataValue::Float(f.0.into())),
|
|
|
|
|
(DataValue::Int(i), DataValue::Bottom) => Ok(DataValue::Int(*i)),
|
|
|
|
|
(DataValue::Float(f), DataValue::Bottom) => Ok(DataValue::Float(f.0.into())),
|
|
|
|
|
(DataValue::Int(i), DataValue::Int(j)) => Ok(DataValue::Int(min(*i, *j))),
|
|
|
|
|
(DataValue::Int(j), DataValue::Float(i)) | (DataValue::Float(i), DataValue::Int(j)) => {
|
|
|
|
|
Ok(DataValue::Float(min(i.clone(), (*j as f64).into())))
|
|
|
|
@ -90,10 +87,33 @@ fn aggr_min(accum: &DataValue, current: &DataValue) -> Result<DataValue> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
define_aggr!(AGGR_MAX, true);
|
|
|
|
|
fn aggr_max(accum: &DataValue, current: &DataValue) -> Result<DataValue> {
|
|
|
|
|
match (accum, current) {
|
|
|
|
|
(DataValue::Bottom, DataValue::Int(i)) => Ok(DataValue::Int(*i)),
|
|
|
|
|
(DataValue::Bottom, DataValue::Float(f)) => Ok(DataValue::Float(f.0.into())),
|
|
|
|
|
(DataValue::Float(f), DataValue::Bottom) => Ok(DataValue::Float(f.0.into())),
|
|
|
|
|
(DataValue::Int(i), DataValue::Int(j)) => Ok(DataValue::Int(max(*i, *j))),
|
|
|
|
|
(DataValue::Int(j), DataValue::Float(i)) | (DataValue::Float(i), DataValue::Int(j)) => {
|
|
|
|
|
Ok(DataValue::Float(max(i.clone(), (*j as f64).into())))
|
|
|
|
|
}
|
|
|
|
|
(DataValue::Float(i), DataValue::Float(j)) => {
|
|
|
|
|
Ok(DataValue::Float(max(i.clone(), j.clone())))
|
|
|
|
|
}
|
|
|
|
|
(i, j) => bail!(
|
|
|
|
|
"cannot compute min: encountered value {:?} for aggregate {:?}",
|
|
|
|
|
j,
|
|
|
|
|
i
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_aggr(name: &str) -> Option<&'static Aggregation> {
|
|
|
|
|
Some(match name {
|
|
|
|
|
"Count" => &AGGR_COUNT,
|
|
|
|
|
"Sum" => &AGGR_SUM,
|
|
|
|
|
"Min" => &AGGR_MIN,
|
|
|
|
|
"Max" => &AGGR_MAX,
|
|
|
|
|
_ => return None,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|