1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use {
crate::{Result, Value},
std::cmp::Ordering,
};
impl Value {
pub fn aggregate_count(self, other: Value) -> Result<Value> {
Ok(Value::Internal(match (self, other) {
(Value::Null, Value::Null) => 0,
(Value::Internal(self_val), Value::Internal(other_val)) => self_val + other_val,
(Value::Internal(val), Value::Null) | (Value::Null, Value::Internal(val)) => val,
(Value::Internal(val), _) | (_, Value::Internal(val)) => val + 1,
(_, _) => 2,
}))
}
pub fn aggregate_min(self, other: Value) -> Result<Value> {
Ok(
if matches!(self.partial_cmp(&other), Some(Ordering::Less))
|| matches!(other, Value::Null)
{
self
} else {
other
},
)
}
pub fn aggregate_max(self, other: Value) -> Result<Value> {
Ok(
if matches!(self.partial_cmp(&other), Some(Ordering::Greater))
|| matches!(other, Value::Null)
{
self
} else {
other
},
)
}
pub fn aggregate_sum(self, other: Value) -> Result<Value> {
other
.if_null(Value::I64(0))
.generic_add(self.if_null(Value::I64(0)))
}
}