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

getdozer / dozer / 4763034755

pending completion
4763034755

Pull #1460

github

GitHub
Merge 2e63b376c into c58df4a0b
Pull Request #1460: Update init.rs

1 of 1 new or added line in 1 file covered. (100.0%)

34417 of 43846 relevant lines covered (78.5%)

12365.38 hits per line

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

85.25
/dozer-sql/src/pipeline/expression/tests/comparison.rs
1
use crate::pipeline::expression::comparison::{
2
    evaluate_eq, evaluate_gt, evaluate_gte, evaluate_lt, evaluate_lte, evaluate_ne, DATE_FORMAT,
3
};
4
use crate::pipeline::expression::execution::Expression;
5
use crate::pipeline::expression::execution::Expression::Literal;
6
use crate::pipeline::expression::tests::test_common::*;
7
use dozer_types::chrono::{DateTime, NaiveDate};
8
use dozer_types::types::{FieldDefinition, FieldType, Record, SourceDefinition};
9
use dozer_types::{
10
    ordered_float::OrderedFloat,
11
    rust_decimal::Decimal,
12
    types::{Field, Schema},
13
};
14
use num_traits::FromPrimitive;
15
use proptest::prelude::*;
16

17
#[test]
1✔
18
fn test_comparison() {
1✔
19
    proptest!(ProptestConfig::with_cases(1000), move |(
1,000✔
20
        u_num1: u64, u_num2: u64, i_num1: i64, i_num2: i64, f_num1: f64, f_num2: f64, d_num1: ArbitraryDecimal, d_num2: ArbitraryDecimal)| {
1,000✔
21
        let row = Record::new(None, vec![]);
1,000✔
22

1,000✔
23
        let uint1 = Literal(Field::UInt(u_num1));
1,000✔
24
        let uint2 = Literal(Field::UInt(u_num2));
1,000✔
25
        let int1 = Literal(Field::Int(i_num1));
1,000✔
26
        let int2 = Literal(Field::Int(i_num2));
1,000✔
27
        let float1 = Literal(Field::Float(OrderedFloat(f_num1)));
1,000✔
28
        let float2 = Literal(Field::Float(OrderedFloat(f_num2)));
1,000✔
29
        let dec1 = Literal(Field::Decimal(d_num1.0));
1,000✔
30
        let dec2 = Literal(Field::Decimal(d_num2.0));
1,000✔
31
        let null = Literal(Field::Null);
1,000✔
32

1,000✔
33
        // eq: UInt
1,000✔
34
        test_eq(&uint1, &uint1, &row, None);
1,000✔
35
        if u_num1 == u_num2 && u_num1 as i64 == i_num1 && u_num1 as f64 == f_num1 && Decimal::from(u_num1) == d_num1.0 {
1,000✔
36
            test_eq(&uint1, &uint2, &row, None);
×
37
            test_eq(&uint1, &int1, &row, None);
×
38
            test_eq(&uint1, &float1, &row, None);
×
39
            test_eq(&uint1, &dec1, &row, None);
×
40
            test_eq(&uint1, &null, &row, Some(Field::Null));
×
41

×
42
            test_gte(&uint1, &uint2, &row, None);
×
43
            test_gte(&uint1, &int1, &row, None);
×
44
            test_gte(&uint1, &float1, &row, None);
×
45
            test_gte(&uint1, &dec1, &row, None);
×
46
            test_gte(&uint1, &null, &row, Some(Field::Null));
×
47

×
48
            test_lte(&uint1, &uint2, &row, None);
×
49
            test_lte(&uint1, &int1, &row, None);
×
50
            test_lte(&uint1, &float1, &row, None);
×
51
            test_lte(&uint1, &dec1, &row, None);
×
52
            test_lte(&uint1, &null, &row, Some(Field::Null));
×
53
        }
1,000✔
54

1,000✔
55
        // eq: Int
1,000✔
56
        test_eq(&int1, &int1, &row, None);
1,000✔
57
        if i_num1 == u_num1 as i64 && i_num1 == i_num2 && i_num1 as f64 == f_num1 && Decimal::from(i_num1) == d_num1.0 {
1,000✔
58
            test_eq(&int1, &uint1, &row, None);
×
59
            test_eq(&int1, &int2, &row, None);
×
60
            test_eq(&int1, &float1, &row, None);
×
61
            test_eq(&int1, &dec1, &row, None);
×
62
            test_eq(&int1, &null, &row, Some(Field::Null));
×
63

×
64
            test_gte(&int1, &uint1, &row, None);
×
65
            test_gte(&int1, &int2, &row, None);
×
66
            test_gte(&int1, &float1, &row, None);
×
67
            test_gte(&int1, &dec1, &row, None);
×
68
            test_gte(&int1, &null, &row, Some(Field::Null));
×
69

×
70
            test_lte(&int1, &uint1, &row, None);
×
71
            test_lte(&int1, &int2, &row, None);
×
72
            test_lte(&int1, &float1, &row, None);
×
73
            test_lte(&int1, &dec1, &row, None);
×
74
            test_lte(&int1, &null, &row, Some(Field::Null));
×
75
        }
1,000✔
76

1,000✔
77
        // eq: Float
1,000✔
78
        test_eq(&float1, &float1, &row, None);
1,000✔
79
        let d_val = Decimal::from_f64(f_num1);
1,000✔
80
        if d_val.is_some() && f_num1 == u_num1 as f64 && f_num1 == i_num1 as f64 && f_num1 == f_num2 && d_val.unwrap() == d_num1.0 {
1,000✔
81
            test_eq(&float1, &uint1, &row, None);
×
82
            test_eq(&float1, &int1, &row, None);
×
83
            test_eq(&float1, &float2, &row, None);
×
84
            test_eq(&float1, &dec1, &row, None);
×
85
            test_eq(&float1, &null, &row, Some(Field::Null));
×
86

×
87
            test_gte(&float1, &uint1, &row, None);
×
88
            test_gte(&float1, &int1, &row, None);
×
89
            test_gte(&float1, &float2, &row, None);
×
90
            test_gte(&float1, &dec1, &row, None);
×
91
            test_gte(&float1, &null, &row, Some(Field::Null));
×
92

×
93
            test_lte(&float1, &uint1, &row, None);
×
94
            test_lte(&float1, &int1, &row, None);
×
95
            test_lte(&float1, &float2, &row, None);
×
96
            test_lte(&float1, &dec1, &row, None);
×
97
            test_lte(&float1, &null, &row, Some(Field::Null));
×
98
        }
1,000✔
99

1,000✔
100
        // eq: Decimal
1,000✔
101
        test_eq(&dec1, &dec1, &row, None);
1,000✔
102
        let d_val = Decimal::from_f64(f_num1);
1,000✔
103
        if d_val.is_some() && d_num1.0 == Decimal::from(u_num1) && d_num1.0 == Decimal::from(i_num1) && d_num1.0 == d_val.unwrap() && d_num1.0 == d_num2.0 {
1,000✔
104
            test_eq(&dec1, &uint1, &row, None);
×
105
            test_eq(&dec1, &int1, &row, None);
×
106
            test_eq(&dec1, &float1, &row, None);
×
107
            test_eq(&dec1, &dec2, &row, None);
×
108
            test_eq(&dec1, &null, &row, Some(Field::Null));
×
109

×
110
            test_gte(&dec1, &uint1, &row, None);
×
111
            test_gte(&dec1, &int1, &row, None);
×
112
            test_gte(&dec1, &float1, &row, None);
×
113
            test_gte(&dec1, &dec2, &row, None);
×
114
            test_gte(&dec1, &null, &row, Some(Field::Null));
×
115

×
116
            test_lte(&dec1, &uint1, &row, None);
×
117
            test_lte(&dec1, &int1, &row, None);
×
118
            test_lte(&dec1, &float1, &row, None);
×
119
            test_lte(&dec1, &dec2, &row, None);
×
120
            test_lte(&dec1, &null, &row, Some(Field::Null));
×
121
        }
1,000✔
122

1,000✔
123
        // eq: Null
1,000✔
124
        test_eq(&null, &uint2, &row, Some(Field::Null));
1,000✔
125
        test_eq(&null, &int2, &row, Some(Field::Null));
1,000✔
126
        test_eq(&null, &float2, &row, Some(Field::Null));
1,000✔
127
        test_eq(&null, &dec2, &row, Some(Field::Null));
1,000✔
128
        test_eq(&null, &null, &row, Some(Field::Null));
1,000✔
129

1,000✔
130
        // not eq: UInt
1,000✔
131
        if u_num1 != u_num2 && u_num1 as i64 != i_num1 && u_num1 as f64 != f_num1 && Decimal::from(u_num1) != d_num1.0 {
1,000✔
132
            test_eq(&uint1, &uint2, &row, Some(Field::Boolean(false)));
1,000✔
133
            test_eq(&uint1, &int1, &row, Some(Field::Boolean(false)));
1,000✔
134
            test_eq(&uint1, &float1, &row, Some(Field::Boolean(false)));
1,000✔
135
            test_eq(&uint1, &dec1, &row, Some(Field::Boolean(false)));
1,000✔
136
            test_eq(&uint1, &null, &row, Some(Field::Null));
1,000✔
137

1,000✔
138
            test_ne(&uint1, &uint2, &row, None);
1,000✔
139
            test_ne(&uint1, &int1, &row, None);
1,000✔
140
            test_ne(&uint1, &float1, &row, None);
1,000✔
141
            test_ne(&uint1, &dec1, &row, None);
1,000✔
142
            test_ne(&uint1, &null, &row, Some(Field::Null));
1,000✔
143
        }
1,000✔
144

1,000✔
145
        // not eq: Int
1,000✔
146
        if i_num1 != u_num1 as i64 && i_num1 != i_num2 && i_num1 as f64 != f_num1 && Decimal::from(i_num1) != d_num1.0 {
1,000✔
147
            test_eq(&int1, &uint1, &row, Some(Field::Boolean(false)));
1,000✔
148
            test_eq(&int1, &int2, &row, Some(Field::Boolean(false)));
1,000✔
149
            test_eq(&int1, &float1, &row, Some(Field::Boolean(false)));
1,000✔
150
            test_eq(&int1, &dec1, &row, Some(Field::Boolean(false)));
1,000✔
151
            test_eq(&int1, &null, &row, Some(Field::Null));
1,000✔
152

1,000✔
153
            test_ne(&int1, &uint1, &row, None);
1,000✔
154
            test_ne(&int1, &int2, &row, None);
1,000✔
155
            test_ne(&int1, &float1, &row, None);
1,000✔
156
            test_ne(&int1, &dec1, &row, None);
1,000✔
157
            test_ne(&int1, &null, &row, Some(Field::Null));
1,000✔
158
        }
1,000✔
159

1,000✔
160
        // not eq: Float
1,000✔
161
        let d_val = Decimal::from_f64(f_num1);
1,000✔
162
        if d_val.is_some() && f_num1 != u_num1 as f64 && f_num1 != i_num1 as f64 && f_num1 != f_num2 && d_val.unwrap() != d_num1.0 {
1,000✔
163
            test_eq(&float1, &uint1, &row, Some(Field::Boolean(false)));
646✔
164
            test_eq(&float1, &int1, &row, Some(Field::Boolean(false)));
646✔
165
            test_eq(&float1, &float2, &row, Some(Field::Boolean(false)));
646✔
166
            test_eq(&float1, &dec1, &row, Some(Field::Boolean(false)));
646✔
167
            test_eq(&float1, &null, &row, Some(Field::Null));
646✔
168

646✔
169
            test_ne(&float1, &uint1, &row, None);
646✔
170
            test_ne(&float1, &int1, &row, None);
646✔
171
            test_ne(&float1, &float2, &row, None);
646✔
172
            test_ne(&float1, &dec1, &row, None);
646✔
173
            test_ne(&float1, &null, &row, Some(Field::Null));
646✔
174
        }
646✔
175

1,000✔
176
        // not eq: Decimal
1,000✔
177
        let d_val = Decimal::from_f64(f_num1);
1,000✔
178
        if d_val.is_some() && d_num1.0 != Decimal::from(u_num1) && d_num1.0 != Decimal::from(i_num1) && d_num1.0 != d_val.unwrap() && d_num1.0 != d_num2.0 {
1,000✔
179
            test_eq(&dec1, &uint1, &row, Some(Field::Boolean(false)));
670✔
180
            test_eq(&dec1, &int1, &row, Some(Field::Boolean(false)));
670✔
181
            test_eq(&dec1, &float1, &row, Some(Field::Boolean(false)));
670✔
182
            test_eq(&dec1, &dec2, &row, Some(Field::Boolean(false)));
670✔
183
            test_eq(&dec1, &null, &row, Some(Field::Null));
670✔
184

670✔
185
            test_ne(&dec1, &uint1, &row, None);
670✔
186
            test_ne(&dec1, &int1, &row, None);
670✔
187
            test_ne(&dec1, &float1, &row, None);
670✔
188
            test_ne(&dec1, &dec2, &row, None);
670✔
189
            test_ne(&dec1, &null, &row, Some(Field::Null));
670✔
190
        }
670✔
191

1,000✔
192
        // not eq: Null
1,000✔
193
        test_eq(&null, &uint2, &row, Some(Field::Null));
1,000✔
194
        test_eq(&null, &int2, &row, Some(Field::Null));
1,000✔
195
        test_eq(&null, &float2, &row, Some(Field::Null));
1,000✔
196
        test_eq(&null, &dec2, &row, Some(Field::Null));
1,000✔
197

1,000✔
198
        test_ne(&null, &uint2, &row, Some(Field::Null));
1,000✔
199
        test_ne(&null, &int2, &row, Some(Field::Null));
1,000✔
200
        test_ne(&null, &float2, &row, Some(Field::Null));
1,000✔
201
        test_ne(&null, &dec2, &row, Some(Field::Null));
1,000✔
202

1,000✔
203
        // gt: UInt
1,000✔
204
        if u_num1 > u_num2 && u_num1 as i64 > i_num1 && u_num1 as f64 > f_num1 && Decimal::from(u_num1) > d_num1.0 {
1,000✔
205
            test_gt(&uint1, &uint2, &row, None);
150✔
206
            test_gt(&uint1, &int1, &row, None);
150✔
207
            test_gt(&uint1, &float1, &row, None);
150✔
208
            test_gt(&uint1, &dec1, &row, None);
150✔
209
            test_gt(&uint1, &null, &row, Some(Field::Null));
150✔
210

150✔
211
            test_gte(&uint1, &uint2, &row, None);
150✔
212
            test_gte(&uint1, &int1, &row, None);
150✔
213
            test_gte(&uint1, &float1, &row, None);
150✔
214
            test_gte(&uint1, &dec1, &row, None);
150✔
215
            test_gte(&uint1, &null, &row, Some(Field::Null));
150✔
216

150✔
217
            test_lt(&uint1, &uint2, &row, Some(Field::Boolean(false)));
150✔
218
            test_lt(&uint1, &int1, &row, Some(Field::Boolean(false)));
150✔
219
            test_lt(&uint1, &float1, &row, Some(Field::Boolean(false)));
150✔
220
            test_lt(&uint1, &dec1, &row, Some(Field::Boolean(false)));
150✔
221
            test_lt(&uint1, &null, &row, Some(Field::Null));
150✔
222

150✔
223
            test_lte(&uint1, &uint2, &row, Some(Field::Boolean(false)));
150✔
224
            test_lte(&uint1, &int1, &row, Some(Field::Boolean(false)));
150✔
225
            test_lte(&uint1, &float1, &row, Some(Field::Boolean(false)));
150✔
226
            test_lte(&uint1, &dec1, &row, Some(Field::Boolean(false)));
150✔
227
            test_lte(&uint1, &null, &row, Some(Field::Null));
150✔
228
        }
850✔
229

1,000✔
230
        // gt: Int
1,000✔
231
        if i_num1 > u_num1 as i64 && i_num1 > i_num2 && i_num1 as f64 > f_num1 && Decimal::from(i_num1) > d_num1.0 {
1,000✔
232
            test_gt(&int1, &uint1, &row, None);
241✔
233
            test_gt(&int1, &int2, &row, None);
241✔
234
            test_gt(&int1, &float1, &row, None);
241✔
235
            test_gt(&int1, &dec1, &row, None);
241✔
236
            test_gt(&int1, &null, &row, Some(Field::Null));
241✔
237

241✔
238
            test_gte(&int1, &uint1, &row, None);
241✔
239
            test_gte(&int1, &int2, &row, None);
241✔
240
            test_gte(&int1, &float1, &row, None);
241✔
241
            test_gte(&int1, &dec1, &row, None);
241✔
242
            test_gte(&int1, &null, &row, Some(Field::Null));
241✔
243

241✔
244
            test_lt(&int1, &uint1, &row, Some(Field::Boolean(false)));
241✔
245
            test_lt(&int1, &int2, &row, Some(Field::Boolean(false)));
241✔
246
            test_lt(&int1, &float1, &row, Some(Field::Boolean(false)));
241✔
247
            test_lt(&int1, &dec1, &row, Some(Field::Boolean(false)));
241✔
248
            test_lt(&int1, &null, &row, Some(Field::Null));
241✔
249

241✔
250
            test_lte(&int1, &uint1, &row, Some(Field::Boolean(false)));
241✔
251
            test_lte(&int1, &int2, &row, Some(Field::Boolean(false)));
241✔
252
            test_lte(&int1, &float1, &row, Some(Field::Boolean(false)));
241✔
253
            test_lte(&int1, &dec1, &row, Some(Field::Boolean(false)));
241✔
254
            test_lte(&int1, &null, &row, Some(Field::Null));
241✔
255
        }
759✔
256

1,000✔
257
        // gt: Float
1,000✔
258
        let d_val = Decimal::from_f64(f_num1);
1,000✔
259
        if d_val.is_some() && f_num1 > u_num1 as f64 && f_num1 > i_num1 as f64 && f_num1 > f_num2 && d_val.unwrap() > d_num1.0 {
1,000✔
260
            test_gt(&float1, &uint1, &row, None);
5✔
261
            test_gt(&float1, &int1, &row, None);
5✔
262
            test_gt(&float1, &float2, &row, None);
5✔
263
            test_gt(&float1, &dec1, &row, None);
5✔
264
            test_gt(&float1, &null, &row, Some(Field::Null));
5✔
265

5✔
266
            test_gte(&float1, &uint1, &row, None);
5✔
267
            test_gte(&float1, &int1, &row, None);
5✔
268
            test_gte(&float1, &float2, &row, None);
5✔
269
            test_gte(&float1, &dec1, &row, None);
5✔
270
            test_gte(&float1, &null, &row, Some(Field::Null));
5✔
271

5✔
272
            test_lt(&float1, &uint1, &row, Some(Field::Boolean(false)));
5✔
273
            test_lt(&float1, &int1, &row, Some(Field::Boolean(false)));
5✔
274
            test_lt(&float1, &float2, &row, Some(Field::Boolean(false)));
5✔
275
            test_lt(&float1, &dec1, &row, Some(Field::Boolean(false)));
5✔
276
            test_lt(&float1, &null, &row, Some(Field::Null));
5✔
277

5✔
278
            test_lte(&float1, &uint1, &row, Some(Field::Boolean(false)));
5✔
279
            test_lte(&float1, &int1, &row, Some(Field::Boolean(false)));
5✔
280
            test_lte(&float1, &float2, &row, Some(Field::Boolean(false)));
5✔
281
            test_lte(&float1, &dec1, &row, Some(Field::Boolean(false)));
5✔
282
            test_lte(&float1, &null, &row, Some(Field::Null));
5✔
283
        }
995✔
284

1,000✔
285
        // gt: Decimal
1,000✔
286
        let d_val = Decimal::from_f64(f_num1);
1,000✔
287
        if d_val.is_some() && d_num1.0 > Decimal::from(u_num1) && d_num1.0 > Decimal::from(i_num1) && d_num1.0 > d_val.unwrap() && d_num1.0 > d_num2.0 {
1,000✔
288
            test_gt(&dec1, &uint1, &row, None);
1✔
289
            test_gt(&dec1, &int1, &row, None);
1✔
290
            test_gt(&dec1, &float1, &row, None);
1✔
291
            test_gt(&dec1, &dec2, &row, None);
1✔
292
            test_gt(&dec1, &null, &row, Some(Field::Null));
1✔
293

1✔
294
            test_gte(&dec1, &uint1, &row, None);
1✔
295
            test_gte(&dec1, &int1, &row, None);
1✔
296
            test_gte(&dec1, &float1, &row, None);
1✔
297
            test_gte(&dec1, &dec2, &row, None);
1✔
298
            test_gte(&dec1, &null, &row, Some(Field::Null));
1✔
299

1✔
300
            test_lt(&dec1, &uint1, &row, Some(Field::Boolean(false)));
1✔
301
            test_lt(&dec1, &int1, &row, Some(Field::Boolean(false)));
1✔
302
            test_lt(&dec1, &float1, &row, Some(Field::Boolean(false)));
1✔
303
            test_lt(&dec1, &dec2, &row, Some(Field::Boolean(false)));
1✔
304
            test_lt(&dec1, &null, &row, Some(Field::Null));
1✔
305

1✔
306
            test_lte(&dec1, &uint1, &row, Some(Field::Boolean(false)));
1✔
307
            test_lte(&dec1, &int1, &row, Some(Field::Boolean(false)));
1✔
308
            test_lt(&dec1, &float1, &row, Some(Field::Boolean(false)));
1✔
309
            test_lte(&dec1, &dec2, &row, Some(Field::Boolean(false)));
1✔
310
            test_lte(&dec1, &null, &row, Some(Field::Null));
1✔
311
        }
999✔
312

1,000✔
313
        // lt: UInt
1,000✔
314
        if u_num1 < u_num2 && (u_num1 as i64) < i_num1 && (u_num1 as f64) < f_num1 && Decimal::from(u_num1) < d_num1.0 {
1,000✔
315
            test_lt(&uint1, &uint2, &row, None);
×
316
            test_lt(&uint1, &int1, &row, None);
×
317
            test_lt(&uint1, &float1, &row, None);
×
318
            test_lt(&uint1, &dec1, &row, None);
×
319
            test_lt(&uint1, &null, &row, Some(Field::Null));
×
320

×
321
            test_lte(&uint1, &uint2, &row, None);
×
322
            test_lte(&uint1, &int1, &row, None);
×
323
            test_lte(&uint1, &float1, &row, None);
×
324
            test_lte(&uint1, &dec1, &row, None);
×
325
            test_lte(&uint1, &null, &row, Some(Field::Null));
×
326

×
327
            test_gt(&uint1, &uint2, &row, Some(Field::Boolean(false)));
×
328
            test_gt(&uint1, &int1, &row, Some(Field::Boolean(false)));
×
329
            test_gt(&uint1, &float1, &row, Some(Field::Boolean(false)));
×
330
            test_gt(&uint1, &dec1, &row, Some(Field::Boolean(false)));
×
331
            test_gt(&uint1, &null, &row, Some(Field::Null));
×
332

×
333
            test_gte(&uint1, &uint2, &row, Some(Field::Boolean(false)));
×
334
            test_gte(&uint1, &int1, &row, Some(Field::Boolean(false)));
×
335
            test_gte(&uint1, &float1, &row, Some(Field::Boolean(false)));
×
336
            test_gte(&uint1, &dec1, &row, Some(Field::Boolean(false)));
×
337
            test_gte(&uint1, &null, &row, Some(Field::Null));
×
338
        }
1,000✔
339

1,000✔
340
        // gt: Int
1,000✔
341
        if i_num1 < (u_num1 as i64) && i_num1 < i_num2 && (i_num1 as f64) < f_num1 && Decimal::from(i_num1) < d_num1.0 {
1,000✔
342
            test_lt(&int1, &uint1, &row, None);
242✔
343
            test_lt(&int1, &int2, &row, None);
242✔
344
            test_lt(&int1, &float1, &row, None);
242✔
345
            test_lt(&int1, &dec1, &row, None);
242✔
346
            test_lt(&int1, &null, &row, Some(Field::Null));
242✔
347

242✔
348
            test_lte(&int1, &uint1, &row, None);
242✔
349
            test_lte(&int1, &int2, &row, None);
242✔
350
            test_lte(&int1, &float1, &row, None);
242✔
351
            test_lte(&int1, &dec1, &row, None);
242✔
352
            test_lte(&int1, &null, &row, Some(Field::Null));
242✔
353

242✔
354
            test_gt(&int1, &uint1, &row, Some(Field::Boolean(false)));
242✔
355
            test_gt(&int1, &int2, &row, Some(Field::Boolean(false)));
242✔
356
            test_gt(&int1, &float1, &row, Some(Field::Boolean(false)));
242✔
357
            test_gt(&int1, &dec1, &row, Some(Field::Boolean(false)));
242✔
358
            test_gt(&int1, &null, &row, Some(Field::Null));
242✔
359

242✔
360
            test_gte(&int1, &uint1, &row, Some(Field::Boolean(false)));
242✔
361
            test_gte(&int1, &int2, &row, Some(Field::Boolean(false)));
242✔
362
            test_gte(&int1, &float1, &row, Some(Field::Boolean(false)));
242✔
363
            test_gte(&int1, &dec1, &row, Some(Field::Boolean(false)));
242✔
364
            test_gte(&int1, &null, &row, Some(Field::Null));
242✔
365
        }
758✔
366

1,000✔
367
        // gt: Float
1,000✔
368
        let d_val = Decimal::from_f64(f_num1);
1,000✔
369
        if d_val.is_some() && f_num1 < u_num1 as f64 && f_num1 < i_num1 as f64 && f_num1 < f_num2 && d_val.unwrap() < d_num1.0 {
1,000✔
370
            test_lt(&float1, &uint1, &row, None);
76✔
371
            test_lt(&float1, &int1, &row, None);
76✔
372
            test_lt(&float1, &float2, &row, None);
76✔
373
            test_lt(&float1, &dec1, &row, None);
76✔
374
            test_lt(&float1, &null, &row, Some(Field::Null));
76✔
375

76✔
376
            test_lte(&float1, &uint1, &row, None);
76✔
377
            test_lte(&float1, &int1, &row, None);
76✔
378
            test_lte(&float1, &float2, &row, None);
76✔
379
            test_lte(&float1, &dec1, &row, None);
76✔
380
            test_lte(&float1, &null, &row, Some(Field::Null));
76✔
381

76✔
382
            test_gt(&float1, &uint1, &row, Some(Field::Boolean(false)));
76✔
383
            test_gt(&float1, &int1, &row, Some(Field::Boolean(false)));
76✔
384
            test_gt(&float1, &float2, &row, Some(Field::Boolean(false)));
76✔
385
            test_gt(&float1, &dec1, &row, Some(Field::Boolean(false)));
76✔
386
            test_gt(&float1, &null, &row, Some(Field::Null));
76✔
387

76✔
388
            test_gte(&float1, &uint1, &row, Some(Field::Boolean(false)));
76✔
389
            test_gte(&float1, &int1, &row, Some(Field::Boolean(false)));
76✔
390
            test_gte(&float1, &float2, &row, Some(Field::Boolean(false)));
76✔
391
            test_gte(&float1, &dec1, &row, Some(Field::Boolean(false)));
76✔
392
            test_gte(&float1, &null, &row, Some(Field::Null));
76✔
393
        }
924✔
394

1,000✔
395
        // gt: Decimal
1,000✔
396
        let d_val = Decimal::from_f64(f_num1);
1,000✔
397
        if d_val.is_some() && d_num1.0 < Decimal::from(u_num1) && d_num1.0 < Decimal::from(i_num1) && d_num1.0 < d_val.unwrap() && d_num1.0 < d_num2.0 {
1,000✔
398
            test_lt(&dec1, &uint1, &row, None);
119✔
399
            test_lt(&dec1, &int1, &row, None);
119✔
400
            test_lt(&dec1, &float1, &row, None);
119✔
401
            test_lt(&dec1, &dec2, &row, None);
119✔
402
            test_lt(&dec1, &null, &row, Some(Field::Null));
119✔
403

119✔
404
            test_lte(&dec1, &uint1, &row, None);
119✔
405
            test_lte(&dec1, &int1, &row, None);
119✔
406
            test_lte(&dec1, &float1, &row, None);
119✔
407
            test_lte(&dec1, &dec2, &row, None);
119✔
408
            test_lte(&dec1, &null, &row, Some(Field::Null));
119✔
409

119✔
410
            test_gt(&dec1, &uint1, &row, Some(Field::Boolean(false)));
119✔
411
            test_gt(&dec1, &int1, &row, Some(Field::Boolean(false)));
119✔
412
            test_gt(&dec1, &float1, &row, Some(Field::Boolean(false)));
119✔
413
            test_gt(&dec1, &dec2, &row, Some(Field::Boolean(false)));
119✔
414
            test_gt(&dec1, &null, &row, Some(Field::Null));
119✔
415

119✔
416
            test_gte(&dec1, &uint1, &row, Some(Field::Boolean(false)));
119✔
417
            test_gte(&dec1, &int1, &row, Some(Field::Boolean(false)));
119✔
418
            test_gte(&dec1, &float1, &row, Some(Field::Boolean(false)));
119✔
419
            test_gte(&dec1, &dec2, &row, Some(Field::Boolean(false)));
119✔
420
            test_gte(&dec1, &null, &row, Some(Field::Null));
119✔
421
        }
881✔
422
    });
1,000✔
423
}
1✔
424

425
fn test_eq(exp1: &Expression, exp2: &Expression, row: &Record, result: Option<Field>) {
29,580✔
426
    match result {
29,580✔
427
        None => {
428
            assert!(matches!(
4,000✔
429
                evaluate_eq(&Schema::empty(), exp1, exp2, row),
4,000✔
430
                Ok(Field::Boolean(true))
431
            ));
432
        }
433
        Some(_val) => {
25,580✔
434
            assert!(matches!(
25,580✔
435
                evaluate_eq(&Schema::empty(), exp1, exp2, row),
25,580✔
436
                Ok(_val)
25,580✔
437
            ));
438
        }
439
    }
440
}
29,580✔
441

442
fn test_ne(exp1: &Expression, exp2: &Expression, row: &Record, result: Option<Field>) {
20,580✔
443
    match result {
20,580✔
444
        None => {
445
            assert!(matches!(
13,264✔
446
                evaluate_ne(&Schema::empty(), exp1, exp2, row),
13,264✔
447
                Ok(Field::Boolean(true))
448
            ));
449
        }
450
        Some(_val) => {
7,316✔
451
            assert!(matches!(
7,316✔
452
                evaluate_ne(&Schema::empty(), exp1, exp2, row),
7,316✔
453
                Ok(_val)
7,316✔
454
            ));
455
        }
456
    }
457
}
20,580✔
458

459
fn test_gt(exp1: &Expression, exp2: &Expression, row: &Record, result: Option<Field>) {
4,170✔
460
    match result {
4,170✔
461
        None => {
462
            assert!(matches!(
1,588✔
463
                evaluate_gt(&Schema::empty(), exp1, exp2, row),
1,588✔
464
                Ok(Field::Boolean(true))
465
            ));
466
        }
467
        Some(_val) => {
2,582✔
468
            assert!(matches!(
2,582✔
469
                evaluate_gt(&Schema::empty(), exp1, exp2, row),
2,582✔
470
                Ok(_val)
2,582✔
471
            ));
472
        }
473
    }
474
}
4,170✔
475

476
fn test_lt(exp1: &Expression, exp2: &Expression, row: &Record, result: Option<Field>) {
4,171✔
477
    match result {
4,171✔
478
        None => {
479
            assert!(matches!(
1,748✔
480
                evaluate_lt(&Schema::empty(), exp1, exp2, row),
1,748✔
481
                Ok(Field::Boolean(true))
482
            ));
483
        }
484
        Some(_val) => {
2,423✔
485
            assert!(matches!(
2,423✔
486
                evaluate_lt(&Schema::empty(), exp1, exp2, row),
2,423✔
487
                Ok(_val)
2,423✔
488
            ));
489
        }
490
    }
491
}
4,171✔
492

493
fn test_gte(exp1: &Expression, exp2: &Expression, row: &Record, result: Option<Field>) {
4,170✔
494
    match result {
4,170✔
495
        None => {
496
            assert!(matches!(
1,588✔
497
                evaluate_gte(&Schema::empty(), exp1, exp2, row),
1,588✔
498
                Ok(Field::Boolean(true))
499
            ));
500
        }
501
        Some(_val) => {
2,582✔
502
            assert!(matches!(
2,582✔
503
                evaluate_gte(&Schema::empty(), exp1, exp2, row),
2,582✔
504
                Ok(_val)
2,582✔
505
            ));
506
        }
507
    }
508
}
4,170✔
509

510
fn test_lte(exp1: &Expression, exp2: &Expression, row: &Record, result: Option<Field>) {
4,169✔
511
    match result {
4,169✔
512
        None => {
513
            assert!(matches!(
1,748✔
514
                evaluate_lte(&Schema::empty(), exp1, exp2, row),
1,748✔
515
                Ok(Field::Boolean(true))
516
            ));
517
        }
518
        Some(_val) => {
2,421✔
519
            assert!(matches!(
2,421✔
520
                evaluate_lte(&Schema::empty(), exp1, exp2, row),
2,421✔
521
                Ok(_val)
2,421✔
522
            ));
523
        }
524
    }
525
}
4,169✔
526

527
#[test]
1✔
528
fn test_comparison_logical_int() {
1✔
529
    let record = vec![Field::Int(124)];
1✔
530
    let schema = Schema::empty()
1✔
531
        .field(
1✔
532
            FieldDefinition::new(
1✔
533
                String::from("id"),
1✔
534
                FieldType::Int,
1✔
535
                false,
1✔
536
                SourceDefinition::Dynamic,
1✔
537
            ),
1✔
538
            false,
1✔
539
        )
1✔
540
        .clone();
1✔
541

1✔
542
    let f = run_fct(
1✔
543
        "SELECT id FROM users WHERE id = '124'",
1✔
544
        schema.clone(),
1✔
545
        record.clone(),
1✔
546
    );
1✔
547
    assert_eq!(f, Field::Int(124));
1✔
548

549
    let f = run_fct(
1✔
550
        "SELECT id FROM users WHERE id <= '124'",
1✔
551
        schema.clone(),
1✔
552
        record.clone(),
1✔
553
    );
1✔
554
    assert_eq!(f, Field::Int(124));
1✔
555

556
    let f = run_fct(
1✔
557
        "SELECT id FROM users WHERE id >= '124'",
1✔
558
        schema.clone(),
1✔
559
        record.clone(),
1✔
560
    );
1✔
561
    assert_eq!(f, Field::Int(124));
1✔
562

563
    let f = run_fct(
1✔
564
        "SELECT id = '124' FROM users",
1✔
565
        schema.clone(),
1✔
566
        record.clone(),
1✔
567
    );
1✔
568
    assert_eq!(f, Field::Boolean(true));
1✔
569

570
    let f = run_fct(
1✔
571
        "SELECT id < '124' FROM users",
1✔
572
        schema.clone(),
1✔
573
        record.clone(),
1✔
574
    );
1✔
575
    assert_eq!(f, Field::Boolean(false));
1✔
576

577
    let f = run_fct(
1✔
578
        "SELECT id > '124' FROM users",
1✔
579
        schema.clone(),
1✔
580
        record.clone(),
1✔
581
    );
1✔
582
    assert_eq!(f, Field::Boolean(false));
1✔
583

584
    let f = run_fct(
1✔
585
        "SELECT id <= '124' FROM users",
1✔
586
        schema.clone(),
1✔
587
        record.clone(),
1✔
588
    );
1✔
589
    assert_eq!(f, Field::Boolean(true));
1✔
590

591
    let f = run_fct("SELECT id >= '124' FROM users", schema, record);
1✔
592
    assert_eq!(f, Field::Boolean(true));
1✔
593
}
1✔
594

595
#[test]
1✔
596
fn test_comparison_logical_timestamp() {
1✔
597
    let f = run_fct(
1✔
598
        "SELECT time = '2020-01-01T00:00:00Z' FROM users",
1✔
599
        Schema::empty()
1✔
600
            .field(
1✔
601
                FieldDefinition::new(
1✔
602
                    String::from("time"),
1✔
603
                    FieldType::Timestamp,
1✔
604
                    false,
1✔
605
                    SourceDefinition::Dynamic,
1✔
606
                ),
1✔
607
                false,
1✔
608
            )
1✔
609
            .clone(),
1✔
610
        vec![Field::Timestamp(
1✔
611
            DateTime::parse_from_rfc3339("2020-01-01T00:00:00Z").unwrap(),
1✔
612
        )],
1✔
613
    );
1✔
614
    assert_eq!(f, Field::Boolean(true));
1✔
615

616
    let f = run_fct(
1✔
617
        "SELECT time < '2020-01-01T00:00:01Z' FROM users",
1✔
618
        Schema::empty()
1✔
619
            .field(
1✔
620
                FieldDefinition::new(
1✔
621
                    String::from("time"),
1✔
622
                    FieldType::Timestamp,
1✔
623
                    false,
1✔
624
                    SourceDefinition::Dynamic,
1✔
625
                ),
1✔
626
                false,
1✔
627
            )
1✔
628
            .clone(),
1✔
629
        vec![Field::Timestamp(
1✔
630
            DateTime::parse_from_rfc3339("2020-01-01T00:00:00Z").unwrap(),
1✔
631
        )],
1✔
632
    );
1✔
633
    assert_eq!(f, Field::Boolean(true));
1✔
634
}
1✔
635

636
#[test]
1✔
637
fn test_comparison_logical_date() {
1✔
638
    let f = run_fct(
1✔
639
        "SELECT date = '2020-01-01' FROM users",
1✔
640
        Schema::empty()
1✔
641
            .field(
1✔
642
                FieldDefinition::new(
1✔
643
                    String::from("date"),
1✔
644
                    FieldType::Int,
1✔
645
                    false,
1✔
646
                    SourceDefinition::Dynamic,
1✔
647
                ),
1✔
648
                false,
1✔
649
            )
1✔
650
            .clone(),
1✔
651
        vec![Field::Date(
1✔
652
            NaiveDate::parse_from_str("2020-01-01", DATE_FORMAT).unwrap(),
1✔
653
        )],
1✔
654
    );
1✔
655
    assert_eq!(f, Field::Boolean(true));
1✔
656

657
    let f = run_fct(
1✔
658
        "SELECT date != '2020-01-01' FROM users",
1✔
659
        Schema::empty()
1✔
660
            .field(
1✔
661
                FieldDefinition::new(
1✔
662
                    String::from("date"),
1✔
663
                    FieldType::Int,
1✔
664
                    false,
1✔
665
                    SourceDefinition::Dynamic,
1✔
666
                ),
1✔
667
                false,
1✔
668
            )
1✔
669
            .clone(),
1✔
670
        vec![Field::Date(
1✔
671
            NaiveDate::parse_from_str("2020-01-01", DATE_FORMAT).unwrap(),
1✔
672
        )],
1✔
673
    );
1✔
674
    assert_eq!(f, Field::Boolean(false));
1✔
675

676
    let f = run_fct(
1✔
677
        "SELECT date > '2020-01-01' FROM users",
1✔
678
        Schema::empty()
1✔
679
            .field(
1✔
680
                FieldDefinition::new(
1✔
681
                    String::from("date"),
1✔
682
                    FieldType::Int,
1✔
683
                    false,
1✔
684
                    SourceDefinition::Dynamic,
1✔
685
                ),
1✔
686
                false,
1✔
687
            )
1✔
688
            .clone(),
1✔
689
        vec![Field::Date(
1✔
690
            NaiveDate::parse_from_str("2020-01-02", DATE_FORMAT).unwrap(),
1✔
691
        )],
1✔
692
    );
1✔
693
    assert_eq!(f, Field::Boolean(true));
1✔
694
}
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

© 2025 Coveralls, Inc