quill_sql/function/aggregate/
count.rs

1use crate::error::QuillSQLResult;
2use crate::function::aggregate::Accumulator;
3use crate::utils::scalar::ScalarValue;
4
5#[derive(Debug, Clone)]
6pub struct CountAccumulator {
7    count: i64,
8}
9
10impl CountAccumulator {
11    pub fn new() -> Self {
12        Self { count: 0 }
13    }
14}
15
16impl Accumulator for CountAccumulator {
17    fn update_value(&mut self, value: &ScalarValue) -> QuillSQLResult<()> {
18        if !value.is_null() {
19            self.count += 1;
20        }
21        Ok(())
22    }
23
24    fn evaluate(&self) -> QuillSQLResult<ScalarValue> {
25        Ok(self.count.into())
26    }
27}