quill_sql/function/aggregate/
count.rs1use 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 Default for CountAccumulator {
11 fn default() -> Self {
12 Self::new()
13 }
14}
15
16impl CountAccumulator {
17 pub fn new() -> Self {
18 Self { count: 0 }
19 }
20}
21
22impl Accumulator for CountAccumulator {
23 fn update_value(&mut self, value: &ScalarValue) -> QuillSQLResult<()> {
24 if !value.is_null() {
25 self.count += 1;
26 }
27 Ok(())
28 }
29
30 fn evaluate(&self) -> QuillSQLResult<ScalarValue> {
31 Ok(self.count.into())
32 }
33}