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

getdozer / dozer / 4361707165

pending completion
4361707165

push

github

GitHub
refactor: comparison errors (#1163)

286 of 286 new or added lines in 3 files covered. (100.0%)

27143 of 35806 relevant lines covered (75.81%)

33477.66 hits per line

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

84.87
/dozer-sql/src/pipeline/expression/logical.rs
1
use crate::pipeline::errors::PipelineError;
2
use crate::pipeline::expression::execution::{Expression, ExpressionExecutor};
3
use dozer_types::types::{Field, Record, Schema};
4

5
pub fn evaluate_and(
6
    schema: &Schema,
7
    left: &Expression,
8
    right: &Expression,
9
    record: &Record,
10
) -> Result<Field, PipelineError> {
11
    match left.evaluate(record, schema)? {
2,026✔
12
        Field::Boolean(true) => match right.evaluate(record, schema)? {
63✔
13
            Field::Boolean(true) => Ok(Field::Boolean(true)),
30✔
14
            Field::Boolean(false) => Ok(Field::Boolean(false)),
32✔
15
            Field::Null => Ok(Field::Boolean(false)),
1✔
16
            not_supported_field => Err(PipelineError::InvalidType(
×
17
                not_supported_field,
×
18
                "AND".to_string(),
×
19
            )),
×
20
        },
21
        Field::Boolean(false) => Ok(Field::Boolean(false)),
1,960✔
22
        Field::Null => Ok(Field::Boolean(false)),
1✔
23
        not_supported_field => Err(PipelineError::InvalidType(
2✔
24
            not_supported_field,
2✔
25
            "AND".to_string(),
2✔
26
        )),
2✔
27
    }
28
}
2,026✔
29

30
pub fn evaluate_or(
31
    schema: &Schema,
32
    left: &Expression,
33
    right: &Expression,
34
    record: &Record,
35
) -> Result<Field, PipelineError> {
36
    match left.evaluate(record, schema)? {
1,013✔
37
        Field::Boolean(true) => Ok(Field::Boolean(true)),
17✔
38
        Field::Boolean(false) | Field::Null => match right.evaluate(record, schema)? {
996✔
39
            Field::Boolean(false) => Ok(Field::Boolean(false)),
245✔
40
            Field::Null => Ok(Field::Boolean(false)),
×
41
            Field::Boolean(true) => Ok(Field::Boolean(true)),
751✔
42
            not_supported_field => Err(PipelineError::InvalidType(
×
43
                not_supported_field,
×
44
                "OR".to_string(),
×
45
            )),
×
46
        },
47
        not_supported_field => Err(PipelineError::InvalidType(
×
48
            not_supported_field,
×
49
            "OR".to_string(),
×
50
        )),
×
51
    }
52
}
1,013✔
53

54
pub fn evaluate_not(
2✔
55
    schema: &Schema,
2✔
56
    value: &Expression,
2✔
57
    record: &Record,
2✔
58
) -> Result<Field, PipelineError> {
2✔
59
    let value_p = value.evaluate(record, schema)?;
2✔
60

61
    match value_p {
2✔
62
        Field::Boolean(value_v) => Ok(Field::Boolean(!value_v)),
2✔
63
        Field::Null => Ok(Field::Null),
×
64
        not_supported_field => Err(PipelineError::InvalidType(
×
65
            not_supported_field,
×
66
            "NOT".to_string(),
×
67
        )),
×
68
    }
69
}
2✔
70

71
#[cfg(test)]
72
use crate::pipeline::expression::execution::Expression::Literal;
73

74
#[test]
1✔
75
fn test_bool_bool_and() {
1✔
76
    let row = Record::new(None, vec![], None);
1✔
77
    let l = Box::new(Literal(Field::Boolean(true)));
1✔
78
    let r = Box::new(Literal(Field::Boolean(false)));
1✔
79
    assert!(matches!(
1✔
80
        evaluate_and(&Schema::empty(), &l, &r, &row)
1✔
81
            .unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
82
        Field::Boolean(false)
83
    ));
84
}
1✔
85

86
#[test]
1✔
87
fn test_bool_null_and() {
1✔
88
    let row = Record::new(None, vec![], None);
1✔
89
    let l = Box::new(Literal(Field::Boolean(true)));
1✔
90
    let r = Box::new(Literal(Field::Null));
1✔
91
    assert!(matches!(
1✔
92
        evaluate_and(&Schema::empty(), &l, &r, &row)
1✔
93
            .unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
94
        Field::Boolean(false)
95
    ));
96
}
1✔
97

98
#[test]
1✔
99
fn test_null_bool_and() {
1✔
100
    let row = Record::new(None, vec![], None);
1✔
101
    let l = Box::new(Literal(Field::Null));
1✔
102
    let r = Box::new(Literal(Field::Boolean(true)));
1✔
103
    assert!(matches!(
1✔
104
        evaluate_and(&Schema::empty(), &l, &r, &row)
1✔
105
            .unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
106
        Field::Boolean(false)
107
    ));
108
}
1✔
109

110
#[test]
1✔
111
fn test_bool_bool_or() {
1✔
112
    let row = Record::new(None, vec![], None);
1✔
113
    let l = Box::new(Literal(Field::Boolean(true)));
1✔
114
    let r = Box::new(Literal(Field::Boolean(false)));
1✔
115
    assert!(matches!(
1✔
116
        evaluate_or(&Schema::empty(), &l, &r, &row).unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
117
        Field::Boolean(true)
118
    ));
119
}
1✔
120

121
#[test]
1✔
122
fn test_null_bool_or() {
1✔
123
    let row = Record::new(None, vec![], None);
1✔
124
    let l = Box::new(Literal(Field::Null));
1✔
125
    let r = Box::new(Literal(Field::Boolean(true)));
1✔
126
    assert!(matches!(
1✔
127
        evaluate_or(&Schema::empty(), &l, &r, &row).unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
128
        Field::Boolean(true)
129
    ));
130
}
1✔
131

132
#[test]
1✔
133
fn test_bool_null_or() {
1✔
134
    let row = Record::new(None, vec![], None);
1✔
135
    let l = Box::new(Literal(Field::Boolean(true)));
1✔
136
    let r = Box::new(Literal(Field::Null));
1✔
137
    assert!(matches!(
1✔
138
        evaluate_or(&Schema::empty(), &l, &r, &row).unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
139
        Field::Boolean(true)
140
    ));
141
}
1✔
142

143
#[test]
1✔
144
fn test_bool_not() {
1✔
145
    let row = Record::new(None, vec![], None);
1✔
146
    let v = Box::new(Literal(Field::Boolean(true)));
1✔
147
    assert!(matches!(
1✔
148
        evaluate_not(&Schema::empty(), &v, &row).unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
149
        Field::Boolean(false)
150
    ));
151
}
1✔
152

153
#[test]
1✔
154
fn test_int_bool_and() {
1✔
155
    let row = Record::new(None, vec![], None);
1✔
156
    let l = Box::new(Literal(Field::Int(1)));
1✔
157
    let r = Box::new(Literal(Field::Boolean(true)));
1✔
158
    assert!(evaluate_and(&Schema::empty(), &l, &r, &row).is_err());
1✔
159
}
1✔
160

161
#[test]
1✔
162
fn test_float_bool_and() {
1✔
163
    let row = Record::new(None, vec![], None);
1✔
164
    let l = Box::new(Literal(Field::Float(
1✔
165
        dozer_types::ordered_float::OrderedFloat(1.1),
1✔
166
    )));
1✔
167
    let r = Box::new(Literal(Field::Boolean(true)));
1✔
168
    assert!(evaluate_and(&Schema::empty(), &l, &r, &row).is_err());
1✔
169
}
1✔
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

© 2026 Coveralls, Inc