use std::fmt::Debug;
use serde::{Deserialize, Serialize};
use super::*;
use crate::aggregation::*;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CountAggregation {
pub field: String,
#[serde(default, deserialize_with = "deserialize_option_f64")]
pub missing: Option<f64>,
}
impl CountAggregation {
pub fn from_field_name(field_name: String) -> Self {
Self {
field: field_name,
missing: None,
}
}
pub fn field_name(&self) -> &str {
&self.field
}
}
#[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct IntermediateCount {
stats: IntermediateStats,
}
impl IntermediateCount {
pub(crate) fn from_stats(stats: IntermediateStats) -> Self {
Self { stats }
}
pub fn merge_fruits(&mut self, other: IntermediateCount) {
self.stats.merge_fruits(other.stats);
}
pub fn finalize(&self) -> Option<f64> {
Some(self.stats.finalize().count as f64)
}
}