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

getdozer / dozer / 5963792840

24 Aug 2023 12:37PM UTC coverage: 75.657% (-0.06%) from 75.714%
5963792840

push

github

web-flow
Run sql-tests with custom libtest-mimic harness (#1901)

46995 of 62116 relevant lines covered (75.66%)

48135.42 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::Record;
9
use dozer_types::types::{FieldDefinition, FieldType, SourceDefinition};
10
use dozer_types::{
11
    ordered_float::OrderedFloat,
12
    rust_decimal::Decimal,
13
    types::{Field, Schema},
14
};
15
use num_traits::FromPrimitive;
16
use proptest::prelude::*;
17

18
#[test]
1✔
19
fn test_comparison() {
1✔
20
    proptest!(ProptestConfig::with_cases(1000), move |(
1,000✔
21
        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✔
22
        let row = Record::new(vec![]);
1,000✔
23

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

1,000✔
34
        // eq: UInt
1,000✔
35
        test_eq(&uint1, &uint1, &row, None);
1,000✔
36
        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✔
37
            test_eq(&uint1, &uint2, &row, None);
×
38
            test_eq(&uint1, &int1, &row, None);
×
39
            test_eq(&uint1, &float1, &row, None);
×
40
            test_eq(&uint1, &dec1, &row, None);
×
41
            test_eq(&uint1, &null, &row, Some(Field::Null));
×
42

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

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

1,000✔
56
        // eq: Int
1,000✔
57
        test_eq(&int1, &int1, &row, None);
1,000✔
58
        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✔
59
            test_eq(&int1, &uint1, &row, None);
×
60
            test_eq(&int1, &int2, &row, None);
×
61
            test_eq(&int1, &float1, &row, None);
×
62
            test_eq(&int1, &dec1, &row, None);
×
63
            test_eq(&int1, &null, &row, Some(Field::Null));
×
64

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

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

1,000✔
78
        // eq: Float
1,000✔
79
        test_eq(&float1, &float1, &row, None);
1,000✔
80
        let d_val = Decimal::from_f64(f_num1);
1,000✔
81
        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✔
82
            test_eq(&float1, &uint1, &row, None);
×
83
            test_eq(&float1, &int1, &row, None);
×
84
            test_eq(&float1, &float2, &row, None);
×
85
            test_eq(&float1, &dec1, &row, None);
×
86
            test_eq(&float1, &null, &row, Some(Field::Null));
×
87

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

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

1,000✔
101
        // eq: Decimal
1,000✔
102
        test_eq(&dec1, &dec1, &row, None);
1,000✔
103
        let d_val = Decimal::from_f64(f_num1);
1,000✔
104
        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✔
105
            test_eq(&dec1, &uint1, &row, None);
×
106
            test_eq(&dec1, &int1, &row, None);
×
107
            test_eq(&dec1, &float1, &row, None);
×
108
            test_eq(&dec1, &dec2, &row, None);
×
109
            test_eq(&dec1, &null, &row, Some(Field::Null));
×
110

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

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

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

1,000✔
131
        // not eq: UInt
1,000✔
132
        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✔
133
            test_eq(&uint1, &uint2, &row, Some(Field::Boolean(false)));
1,000✔
134
            test_eq(&uint1, &int1, &row, Some(Field::Boolean(false)));
1,000✔
135
            test_eq(&uint1, &float1, &row, Some(Field::Boolean(false)));
1,000✔
136
            test_eq(&uint1, &dec1, &row, Some(Field::Boolean(false)));
1,000✔
137
            test_eq(&uint1, &null, &row, Some(Field::Null));
1,000✔
138

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

1,000✔
146
        // not eq: Int
1,000✔
147
        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✔
148
            test_eq(&int1, &uint1, &row, Some(Field::Boolean(false)));
1,000✔
149
            test_eq(&int1, &int2, &row, Some(Field::Boolean(false)));
1,000✔
150
            test_eq(&int1, &float1, &row, Some(Field::Boolean(false)));
1,000✔
151
            test_eq(&int1, &dec1, &row, Some(Field::Boolean(false)));
1,000✔
152
            test_eq(&int1, &null, &row, Some(Field::Null));
1,000✔
153

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

1,000✔
161
        // not eq: Float
1,000✔
162
        let d_val = Decimal::from_f64(f_num1);
1,000✔
163
        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✔
164
            test_eq(&float1, &uint1, &row, Some(Field::Boolean(false)));
658✔
165
            test_eq(&float1, &int1, &row, Some(Field::Boolean(false)));
658✔
166
            test_eq(&float1, &float2, &row, Some(Field::Boolean(false)));
658✔
167
            test_eq(&float1, &dec1, &row, Some(Field::Boolean(false)));
658✔
168
            test_eq(&float1, &null, &row, Some(Field::Null));
658✔
169

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

1,000✔
177
        // not eq: Decimal
1,000✔
178
        let d_val = Decimal::from_f64(f_num1);
1,000✔
179
        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✔
180
            test_eq(&dec1, &uint1, &row, Some(Field::Boolean(false)));
676✔
181
            test_eq(&dec1, &int1, &row, Some(Field::Boolean(false)));
676✔
182
            test_eq(&dec1, &float1, &row, Some(Field::Boolean(false)));
676✔
183
            test_eq(&dec1, &dec2, &row, Some(Field::Boolean(false)));
676✔
184
            test_eq(&dec1, &null, &row, Some(Field::Null));
676✔
185

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

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

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

1,000✔
204
        // gt: UInt
1,000✔
205
        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✔
206
            test_gt(&uint1, &uint2, &row, None);
164✔
207
            test_gt(&uint1, &int1, &row, None);
164✔
208
            test_gt(&uint1, &float1, &row, None);
164✔
209
            test_gt(&uint1, &dec1, &row, None);
164✔
210
            test_gt(&uint1, &null, &row, Some(Field::Null));
164✔
211

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

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

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

1,000✔
231
        // gt: Int
1,000✔
232
        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✔
233
            test_gt(&int1, &uint1, &row, None);
233✔
234
            test_gt(&int1, &int2, &row, None);
233✔
235
            test_gt(&int1, &float1, &row, None);
233✔
236
            test_gt(&int1, &dec1, &row, None);
233✔
237
            test_gt(&int1, &null, &row, Some(Field::Null));
233✔
238

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

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

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

1,000✔
258
        // gt: Float
1,000✔
259
        let d_val = Decimal::from_f64(f_num1);
1,000✔
260
        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✔
261
            test_gt(&float1, &uint1, &row, None);
5✔
262
            test_gt(&float1, &int1, &row, None);
5✔
263
            test_gt(&float1, &float2, &row, None);
5✔
264
            test_gt(&float1, &dec1, &row, None);
5✔
265
            test_gt(&float1, &null, &row, Some(Field::Null));
5✔
266

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

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

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

1,000✔
286
        // gt: Decimal
1,000✔
287
        let d_val = Decimal::from_f64(f_num1);
1,000✔
288
        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✔
289
            test_gt(&dec1, &uint1, &row, None);
1✔
290
            test_gt(&dec1, &int1, &row, None);
1✔
291
            test_gt(&dec1, &float1, &row, None);
1✔
292
            test_gt(&dec1, &dec2, &row, None);
1✔
293
            test_gt(&dec1, &null, &row, Some(Field::Null));
1✔
294

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

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

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

1,000✔
314
        // lt: UInt
1,000✔
315
        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✔
316
            test_lt(&uint1, &uint2, &row, None);
×
317
            test_lt(&uint1, &int1, &row, None);
×
318
            test_lt(&uint1, &float1, &row, None);
×
319
            test_lt(&uint1, &dec1, &row, None);
×
320
            test_lt(&uint1, &null, &row, Some(Field::Null));
×
321

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

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

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

1,000✔
341
        // gt: Int
1,000✔
342
        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✔
343
            test_lt(&int1, &uint1, &row, None);
251✔
344
            test_lt(&int1, &int2, &row, None);
251✔
345
            test_lt(&int1, &float1, &row, None);
251✔
346
            test_lt(&int1, &dec1, &row, None);
251✔
347
            test_lt(&int1, &null, &row, Some(Field::Null));
251✔
348

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

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

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

1,000✔
368
        // gt: Float
1,000✔
369
        let d_val = Decimal::from_f64(f_num1);
1,000✔
370
        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✔
371
            test_lt(&float1, &uint1, &row, None);
91✔
372
            test_lt(&float1, &int1, &row, None);
91✔
373
            test_lt(&float1, &float2, &row, None);
91✔
374
            test_lt(&float1, &dec1, &row, None);
91✔
375
            test_lt(&float1, &null, &row, Some(Field::Null));
91✔
376

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

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

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

1,000✔
396
        // gt: Decimal
1,000✔
397
        let d_val = Decimal::from_f64(f_num1);
1,000✔
398
        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✔
399
            test_lt(&dec1, &uint1, &row, None);
131✔
400
            test_lt(&dec1, &int1, &row, None);
131✔
401
            test_lt(&dec1, &float1, &row, None);
131✔
402
            test_lt(&dec1, &dec2, &row, None);
131✔
403
            test_lt(&dec1, &null, &row, Some(Field::Null));
131✔
404

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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