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

getdozer / dozer / 4007820649

pending completion
4007820649

Pull #734

github

GitHub
Merge b71e66da1 into 6c0ac2b2c
Pull Request #734: Bump ahash from 0.8.2 to 0.8.3

23507 of 35166 relevant lines covered (66.85%)

40241.5 hits per line

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

96.92
/dozer-sql/src/pipeline/expression/scalar/tests/string.rs
1
use crate::pipeline::expression::execution::Expression::Literal;
2
use crate::pipeline::expression::scalar::{
3
    string::evaluate_like, tests::scalar_common::run_scalar_fct,
4
};
5
use dozer_types::types::{Field, FieldDefinition, FieldType, Record, Schema, SourceDefinition};
6

7
#[test]
1✔
8
fn test_concat() {
1✔
9
    let f = run_scalar_fct(
1✔
10
        "SELECT CONCAT(fn, ln, fn) FROM USERS",
1✔
11
        Schema::empty()
1✔
12
            .field(
1✔
13
                FieldDefinition::new(
1✔
14
                    String::from("fn"),
1✔
15
                    FieldType::String,
1✔
16
                    false,
1✔
17
                    SourceDefinition::Dynamic,
1✔
18
                ),
1✔
19
                false,
1✔
20
            )
1✔
21
            .field(
1✔
22
                FieldDefinition::new(
1✔
23
                    String::from("ln"),
1✔
24
                    FieldType::String,
1✔
25
                    false,
1✔
26
                    SourceDefinition::Dynamic,
1✔
27
                ),
1✔
28
                false,
1✔
29
            )
1✔
30
            .clone(),
1✔
31
        vec![
1✔
32
            Field::String("John".to_string()),
1✔
33
            Field::String("Doe".to_string()),
1✔
34
        ],
1✔
35
    );
1✔
36
    assert_eq!(f, Field::String("JohnDoeJohn".to_string()));
1✔
37
}
1✔
38

×
39
#[test]
1✔
40
fn test_concat_text() {
1✔
41
    let f = run_scalar_fct(
1✔
42
        "SELECT CONCAT(fn, ln, fn) FROM USERS",
1✔
43
        Schema::empty()
1✔
44
            .field(
1✔
45
                FieldDefinition::new(
1✔
46
                    String::from("fn"),
1✔
47
                    FieldType::Text,
1✔
48
                    false,
1✔
49
                    SourceDefinition::Dynamic,
1✔
50
                ),
1✔
51
                false,
1✔
52
            )
1✔
53
            .field(
1✔
54
                FieldDefinition::new(
1✔
55
                    String::from("ln"),
1✔
56
                    FieldType::String,
1✔
57
                    false,
1✔
58
                    SourceDefinition::Dynamic,
1✔
59
                ),
1✔
60
                false,
1✔
61
            )
1✔
62
            .clone(),
1✔
63
        vec![
1✔
64
            Field::Text("John".to_string()),
1✔
65
            Field::String("Doe".to_string()),
1✔
66
        ],
1✔
67
    );
1✔
68
    assert_eq!(f, Field::Text("JohnDoeJohn".to_string()));
1✔
69
}
1✔
70

×
71
#[test]
1✔
72
fn test_concat_text_empty() {
1✔
73
    let f = run_scalar_fct(
1✔
74
        "SELECT CONCAT() FROM USERS",
1✔
75
        Schema::empty()
1✔
76
            .field(
1✔
77
                FieldDefinition::new(
1✔
78
                    String::from("fn"),
1✔
79
                    FieldType::String,
1✔
80
                    false,
1✔
81
                    SourceDefinition::Dynamic,
1✔
82
                ),
1✔
83
                false,
1✔
84
            )
1✔
85
            .field(
1✔
86
                FieldDefinition::new(
1✔
87
                    String::from("ln"),
1✔
88
                    FieldType::String,
1✔
89
                    false,
1✔
90
                    SourceDefinition::Dynamic,
1✔
91
                ),
1✔
92
                false,
1✔
93
            )
1✔
94
            .clone(),
1✔
95
        vec![
1✔
96
            Field::String("John".to_string()),
1✔
97
            Field::String("Doe".to_string()),
1✔
98
        ],
1✔
99
    );
1✔
100
    assert_eq!(f, Field::String("".to_string()));
1✔
101
}
1✔
102

×
103
#[test]
1✔
104
#[should_panic]
×
105
fn test_concat_wrong_schema() {
1✔
106
    let f = run_scalar_fct(
1✔
107
        "SELECT CONCAT(fn, ln) FROM USERS",
1✔
108
        Schema::empty()
1✔
109
            .field(
1✔
110
                FieldDefinition::new(
1✔
111
                    String::from("fn"),
1✔
112
                    FieldType::String,
1✔
113
                    false,
1✔
114
                    SourceDefinition::Dynamic,
1✔
115
                ),
1✔
116
                false,
1✔
117
            )
1✔
118
            .field(
1✔
119
                FieldDefinition::new(
1✔
120
                    String::from("ln"),
1✔
121
                    FieldType::Int,
1✔
122
                    false,
1✔
123
                    SourceDefinition::Dynamic,
1✔
124
                ),
1✔
125
                false,
1✔
126
            )
1✔
127
            .clone(),
1✔
128
        vec![Field::String("John".to_string()), Field::Int(0)],
1✔
129
    );
1✔
130
    assert_eq!(f, Field::String("JohnDoe".to_string()));
1✔
131
}
1✔
132

×
133
#[test]
1✔
134
fn test_ucase() {
1✔
135
    let f = run_scalar_fct(
1✔
136
        "SELECT UCASE(fn) FROM USERS",
1✔
137
        Schema::empty()
1✔
138
            .field(
1✔
139
                FieldDefinition::new(
1✔
140
                    String::from("fn"),
1✔
141
                    FieldType::String,
1✔
142
                    false,
1✔
143
                    SourceDefinition::Dynamic,
1✔
144
                ),
1✔
145
                false,
1✔
146
            )
1✔
147
            .clone(),
1✔
148
        vec![Field::String("John".to_string())],
1✔
149
    );
1✔
150
    assert_eq!(f, Field::String("JOHN".to_string()));
1✔
151
}
1✔
152

153
#[test]
1✔
154
fn test_ucase_text() {
1✔
155
    let f = run_scalar_fct(
1✔
156
        "SELECT UCASE(fn) FROM USERS",
1✔
157
        Schema::empty()
1✔
158
            .field(
1✔
159
                FieldDefinition::new(
1✔
160
                    String::from("fn"),
1✔
161
                    FieldType::Text,
1✔
162
                    false,
1✔
163
                    SourceDefinition::Dynamic,
1✔
164
                ),
1✔
165
                false,
1✔
166
            )
1✔
167
            .clone(),
1✔
168
        vec![Field::Text("John".to_string())],
1✔
169
    );
1✔
170
    assert_eq!(f, Field::Text("JOHN".to_string()));
1✔
171
}
1✔
172

×
173
#[test]
1✔
174
fn test_length() {
1✔
175
    let f = run_scalar_fct(
1✔
176
        "SELECT LENGTH(fn) FROM USERS",
1✔
177
        Schema::empty()
1✔
178
            .field(
1✔
179
                FieldDefinition::new(
1✔
180
                    String::from("fn"),
1✔
181
                    FieldType::String,
1✔
182
                    false,
1✔
183
                    SourceDefinition::Dynamic,
1✔
184
                ),
1✔
185
                false,
1✔
186
            )
1✔
187
            .clone(),
1✔
188
        vec![Field::String("John".to_string())],
1✔
189
    );
1✔
190
    assert_eq!(f, Field::UInt(4));
1✔
191
}
1✔
192

×
193
#[test]
1✔
194
fn test_trim() {
1✔
195
    let f = run_scalar_fct(
1✔
196
        "SELECT TRIM(fn) FROM USERS",
1✔
197
        Schema::empty()
1✔
198
            .field(
1✔
199
                FieldDefinition::new(
1✔
200
                    String::from("fn"),
1✔
201
                    FieldType::String,
1✔
202
                    false,
1✔
203
                    SourceDefinition::Dynamic,
1✔
204
                ),
1✔
205
                false,
1✔
206
            )
1✔
207
            .clone(),
1✔
208
        vec![Field::String("   John   ".to_string())],
1✔
209
    );
1✔
210
    assert_eq!(f, Field::String("John".to_string()));
1✔
211
}
1✔
212

213
#[test]
1✔
214
fn test_trim_null() {
1✔
215
    let f = run_scalar_fct(
1✔
216
        "SELECT TRIM(fn) FROM USERS",
1✔
217
        Schema::empty()
1✔
218
            .field(
1✔
219
                FieldDefinition::new(
1✔
220
                    String::from("fn"),
1✔
221
                    FieldType::String,
1✔
222
                    false,
1✔
223
                    SourceDefinition::Dynamic,
1✔
224
                ),
1✔
225
                false,
1✔
226
            )
1✔
227
            .clone(),
1✔
228
        vec![Field::Null],
1✔
229
    );
1✔
230
    assert_eq!(f, Field::String("".to_string()));
1✔
231
}
1✔
232

×
233
#[test]
1✔
234
fn test_trim_text() {
1✔
235
    let f = run_scalar_fct(
1✔
236
        "SELECT TRIM(fn) FROM USERS",
1✔
237
        Schema::empty()
1✔
238
            .field(
1✔
239
                FieldDefinition::new(
1✔
240
                    String::from("fn"),
1✔
241
                    FieldType::Text,
1✔
242
                    false,
1✔
243
                    SourceDefinition::Dynamic,
1✔
244
                ),
1✔
245
                false,
1✔
246
            )
1✔
247
            .clone(),
1✔
248
        vec![Field::Text("   John   ".to_string())],
1✔
249
    );
1✔
250
    assert_eq!(f, Field::Text("John".to_string()));
1✔
251
}
1✔
252

×
253
#[test]
1✔
254
fn test_trim_value() {
1✔
255
    let f = run_scalar_fct(
1✔
256
        "SELECT TRIM('_' FROM fn) FROM USERS",
1✔
257
        Schema::empty()
1✔
258
            .field(
1✔
259
                FieldDefinition::new(
1✔
260
                    String::from("fn"),
1✔
261
                    FieldType::String,
1✔
262
                    false,
1✔
263
                    SourceDefinition::Dynamic,
1✔
264
                ),
1✔
265
                false,
1✔
266
            )
1✔
267
            .clone(),
1✔
268
        vec![Field::String("___John___".to_string())],
1✔
269
    );
1✔
270
    assert_eq!(f, Field::String("John".to_string()));
1✔
271
}
1✔
272

×
273
#[test]
1✔
274
fn test_btrim_value() {
1✔
275
    let f = run_scalar_fct(
1✔
276
        "SELECT TRIM(BOTH '_' FROM fn) FROM USERS",
1✔
277
        Schema::empty()
1✔
278
            .field(
1✔
279
                FieldDefinition::new(
1✔
280
                    String::from("fn"),
1✔
281
                    FieldType::String,
1✔
282
                    false,
1✔
283
                    SourceDefinition::Dynamic,
1✔
284
                ),
1✔
285
                false,
1✔
286
            )
1✔
287
            .clone(),
1✔
288
        vec![Field::String("___John___".to_string())],
1✔
289
    );
1✔
290
    assert_eq!(f, Field::String("John".to_string()));
1✔
291
}
1✔
292

×
293
#[test]
1✔
294
fn test_ltrim_value() {
1✔
295
    let f = run_scalar_fct(
1✔
296
        "SELECT TRIM(LEADING '_' FROM fn) FROM USERS",
1✔
297
        Schema::empty()
1✔
298
            .field(
1✔
299
                FieldDefinition::new(
1✔
300
                    String::from("fn"),
1✔
301
                    FieldType::String,
1✔
302
                    false,
1✔
303
                    SourceDefinition::Dynamic,
1✔
304
                ),
1✔
305
                false,
1✔
306
            )
1✔
307
            .clone(),
1✔
308
        vec![Field::String("___John___".to_string())],
1✔
309
    );
1✔
310
    assert_eq!(f, Field::String("John___".to_string()));
1✔
311
}
1✔
312

×
313
#[test]
1✔
314
fn test_ttrim_value() {
1✔
315
    let f = run_scalar_fct(
1✔
316
        "SELECT TRIM(TRAILING '_' FROM fn) FROM USERS",
1✔
317
        Schema::empty()
1✔
318
            .field(
1✔
319
                FieldDefinition::new(
1✔
320
                    String::from("fn"),
1✔
321
                    FieldType::String,
1✔
322
                    false,
1✔
323
                    SourceDefinition::Dynamic,
1✔
324
                ),
1✔
325
                false,
1✔
326
            )
1✔
327
            .clone(),
1✔
328
        vec![Field::String("___John___".to_string())],
1✔
329
    );
1✔
330
    assert_eq!(f, Field::String("___John".to_string()));
1✔
331
}
1✔
332

×
333
#[test]
1✔
334
fn test_like() {
1✔
335
    let row = Record::new(None, vec![], None);
1✔
336

1✔
337
    let value = Box::new(Literal(Field::String("Hello, World!".to_owned())));
1✔
338
    let pattern = Box::new(Literal(Field::String("Hello%".to_owned())));
1✔
339

1✔
340
    assert_eq!(
1✔
341
        evaluate_like(&Schema::empty(), &value, &pattern, None, &row).unwrap(),
1✔
342
        Field::Boolean(true)
1✔
343
    );
1✔
344

345
    let value = Box::new(Literal(Field::String("Hello, World!".to_owned())));
1✔
346
    let pattern = Box::new(Literal(Field::String("Hello, _orld!".to_owned())));
1✔
347

1✔
348
    assert_eq!(
1✔
349
        evaluate_like(&Schema::empty(), &value, &pattern, None, &row).unwrap(),
1✔
350
        Field::Boolean(true)
1✔
351
    );
1✔
352

353
    let value = Box::new(Literal(Field::String("Bye, World!".to_owned())));
1✔
354
    let pattern = Box::new(Literal(Field::String("Hello%".to_owned())));
1✔
355

1✔
356
    assert_eq!(
1✔
357
        evaluate_like(&Schema::empty(), &value, &pattern, None, &row).unwrap(),
1✔
358
        Field::Boolean(false)
1✔
359
    );
1✔
360

361
    let value = Box::new(Literal(Field::String("Hello, World!".to_owned())));
1✔
362
    let pattern = Box::new(Literal(Field::String("Hello, _!".to_owned())));
1✔
363

1✔
364
    assert_eq!(
1✔
365
        evaluate_like(&Schema::empty(), &value, &pattern, None, &row).unwrap(),
1✔
366
        Field::Boolean(false)
1✔
367
    );
1✔
368

369
    let value = Box::new(Literal(Field::String("Hello, $%".to_owned())));
1✔
370
    let pattern = Box::new(Literal(Field::String("Hello, %".to_owned())));
1✔
371
    let escape = Some('$');
1✔
372

1✔
373
    assert_eq!(
1✔
374
        evaluate_like(&Schema::empty(), &value, &pattern, escape, &row).unwrap(),
1✔
375
        Field::Boolean(true)
1✔
376
    );
1✔
377
}
1✔
378

379
#[test]
1✔
380
fn test_like_value() {
1✔
381
    let f = run_scalar_fct(
1✔
382
        "SELECT first_name FROM users WHERE first_name LIKE 'J%'",
1✔
383
        Schema::empty()
1✔
384
            .field(
1✔
385
                FieldDefinition::new(
1✔
386
                    String::from("first_name"),
1✔
387
                    FieldType::String,
1✔
388
                    false,
1✔
389
                    SourceDefinition::Dynamic,
1✔
390
                ),
1✔
391
                false,
1✔
392
            )
1✔
393
            .clone(),
1✔
394
        vec![Field::String("John".to_string())],
1✔
395
    );
1✔
396
    assert_eq!(f, Field::String("John".to_string()));
1✔
397
}
1✔
398

399
#[test]
1✔
400
fn test_not_like_value() {
1✔
401
    let f = run_scalar_fct(
1✔
402
        "SELECT first_name FROM users WHERE first_name NOT LIKE 'A%'",
1✔
403
        Schema::empty()
1✔
404
            .field(
1✔
405
                FieldDefinition::new(
1✔
406
                    String::from("first_name"),
1✔
407
                    FieldType::String,
1✔
408
                    false,
1✔
409
                    SourceDefinition::Dynamic,
1✔
410
                ),
1✔
411
                false,
1✔
412
            )
1✔
413
            .clone(),
1✔
414
        vec![Field::String("John".to_string())],
1✔
415
    );
1✔
416
    assert_eq!(f, Field::String("John".to_string()));
1✔
417
}
1✔
418

419
#[test]
1✔
420
fn test_like_escape() {
1✔
421
    let f = run_scalar_fct(
1✔
422
        "SELECT first_name FROM users WHERE first_name LIKE 'J$%'",
1✔
423
        Schema::empty()
1✔
424
            .field(
1✔
425
                FieldDefinition::new(
1✔
426
                    String::from("first_name"),
1✔
427
                    FieldType::String,
1✔
428
                    false,
1✔
429
                    SourceDefinition::Dynamic,
1✔
430
                ),
1✔
431
                false,
1✔
432
            )
1✔
433
            .clone(),
1✔
434
        vec![Field::String("J%".to_string())],
1✔
435
    );
1✔
436
    assert_eq!(f, Field::String("J%".to_string()));
1✔
437
}
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