use crate::{util::*, Aggregation, Number};
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct BoxplotAggregation {
boxplot: BoxplotAggregationInner,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
struct BoxplotAggregationInner {
field: String,
#[serde(default, skip_serializing_if = "ShouldSkip::should_skip")]
compression: Option<Number>,
#[serde(default, skip_serializing_if = "ShouldSkip::should_skip")]
missing: Option<Number>,
}
impl Aggregation {
pub fn boxplot<T>(field: T) -> BoxplotAggregation
where
T: ToString,
{
BoxplotAggregation {
boxplot: BoxplotAggregationInner {
field: field.to_string(),
compression: None,
missing: None,
},
}
}
}
impl BoxplotAggregation {
pub fn compression<T>(mut self, compression: T) -> Self
where
T: Into<Number>,
{
self.boxplot.compression = Some(compression.into());
self
}
pub fn missing<T>(mut self, missing: T) -> Self
where
T: Into<Number>,
{
self.boxplot.missing = Some(missing.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serialization() {
assert_serialize_aggregation(
Aggregation::boxplot("test_field"),
json!({ "boxplot": { "field": "test_field" } }),
);
assert_serialize_aggregation(
Aggregation::boxplot("test_field")
.compression(100)
.missing(10),
json!({
"boxplot": {
"field": "test_field",
"compression": 100,
"missing": 10
}
}),
);
}
}