• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

flowlight0 / simpledb-rs / #112

20 Jun 2025 10:25AM UTC coverage: 79.857% (+0.2%) from 79.678%
#112

push

web-flow
Implement aggregation functions (#113)

* Add aggregation functions and tests

* Update README.md

76 of 86 new or added lines in 4 files covered. (88.37%)

1 existing line in 1 file now uncovered.

2894 of 3624 relevant lines covered (79.86%)

1.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/materialization/sum_function.rs
1
use crate::{
2
    errors::TransactionError,
3
    record::field::Value,
4
    scan::{Scan, ScanControl},
5
};
6

7
use super::aggregation_function::AggregationFnControl;
8

9
#[derive(Clone)]
10
pub struct SumFn {
11
    sum: i64,
12
    field_name: String,
13
    has_value: bool,
14
}
15

16
impl SumFn {
17
    pub fn new(field_name: &str) -> Self {
1✔
18
        Self {
19
            sum: 0,
20
            field_name: field_name.to_string(),
1✔
21
            has_value: false,
22
        }
23
    }
24
}
25

26
impl AggregationFnControl for SumFn {
27
    fn process_first(&mut self, scan: &mut Scan) -> Result<(), TransactionError> {
1✔
28
        self.sum = 0;
1✔
29
        self.has_value = false;
1✔
30
        match scan.get_value(&self.field_name)? {
1✔
31
            Value::I32(i) => {
1✔
32
                self.sum = i as i64;
1✔
33
                self.has_value = true;
1✔
34
            }
35
            Value::Null => {}
NEW
36
            _ => panic!("Field {} is not an integer", self.field_name),
×
37
        }
38
        Ok(())
1✔
39
    }
40

41
    fn process_next(&mut self, scan: &mut Scan) -> Result<(), TransactionError> {
1✔
42
        match scan.get_value(&self.field_name)? {
1✔
43
            Value::I32(i) => {
1✔
44
                self.sum += i as i64;
2✔
45
                self.has_value = true;
1✔
46
            }
47
            Value::Null => {}
NEW
48
            _ => panic!("Field {} is not an integer", self.field_name),
×
49
        }
50
        Ok(())
1✔
51
    }
52

53
    fn get_field_name(&self) -> &str {
1✔
54
        &self.field_name
1✔
55
    }
56

57
    fn get_value(&self) -> Option<Value> {
1✔
58
        if self.has_value {
1✔
59
            Some(Value::I32(self.sum as i32))
1✔
60
        } else {
NEW
61
            None
×
62
        }
63
    }
64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc