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

getdozer / dozer / 6008856021

29 Aug 2023 06:44AM UTC coverage: 76.756% (-1.0%) from 77.736%
6008856021

push

github

web-flow
chore: Remove unused generic type parameter in `dozer-core` (#1929)

330 of 330 new or added lines in 38 files covered. (100.0%)

48977 of 63809 relevant lines covered (76.76%)

48470.73 hits per line

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

93.82
/dozer-sql/src/pipeline/expression/tests/execution.rs
1
use crate::pipeline::expression::execution::Expression;
2
use crate::pipeline::expression::mathematical::evaluate_sub;
3
use crate::pipeline::expression::operator::{BinaryOperatorType, UnaryOperatorType};
4
use crate::pipeline::expression::scalar::common::ScalarFunctionType;
5
use crate::pipeline::projection::factory::ProjectionProcessorFactory;
6
use crate::pipeline::tests::utils::get_select;
7
use dozer_core::node::ProcessorFactory;
8
use dozer_core::DEFAULT_PORT_HANDLE;
9
use dozer_types::chrono::DateTime;
10
use dozer_types::types::Record;
11
use dozer_types::types::{
12
    DozerDuration, Field, FieldDefinition, FieldType, Schema, SourceDefinition, TimeUnit,
13
};
14

15
#[test]
1✔
16
fn test_column_execution() {
1✔
17
    use dozer_types::ordered_float::OrderedFloat;
1✔
18

1✔
19
    let schema = Schema::default()
1✔
20
        .field(
1✔
21
            FieldDefinition::new(
1✔
22
                "int_field".to_string(),
1✔
23
                FieldType::Int,
1✔
24
                false,
1✔
25
                SourceDefinition::Dynamic,
1✔
26
            ),
1✔
27
            false,
1✔
28
        )
1✔
29
        .field(
1✔
30
            FieldDefinition::new(
1✔
31
                "str_field".to_string(),
1✔
32
                FieldType::String,
1✔
33
                false,
1✔
34
                SourceDefinition::Dynamic,
1✔
35
            ),
1✔
36
            false,
1✔
37
        )
1✔
38
        .field(
1✔
39
            FieldDefinition::new(
1✔
40
                "float_field".to_string(),
1✔
41
                FieldType::Float,
1✔
42
                false,
1✔
43
                SourceDefinition::Dynamic,
1✔
44
            ),
1✔
45
            false,
1✔
46
        )
1✔
47
        .clone();
1✔
48

1✔
49
    let record = Record::new(vec![
1✔
50
        Field::Int(1337),
1✔
51
        Field::String("test".to_string()),
1✔
52
        Field::Float(OrderedFloat(10.10)),
1✔
53
    ]);
1✔
54

1✔
55
    // Column
1✔
56
    let e = Expression::Column { index: 0 };
1✔
57
    assert_eq!(
1✔
58
        e.evaluate(&record, &schema)
1✔
59
            .unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
60
        Field::Int(1337)
1✔
61
    );
1✔
62

×
63
    let e = Expression::Column { index: 1 };
1✔
64
    assert_eq!(
1✔
65
        e.evaluate(&record, &schema)
1✔
66
            .unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
67
        Field::String("test".to_string())
1✔
68
    );
1✔
69

×
70
    let e = Expression::Column { index: 2 };
1✔
71
    assert_eq!(
1✔
72
        e.evaluate(&record, &schema)
1✔
73
            .unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
74
        Field::Float(OrderedFloat(10.10))
1✔
75
    );
1✔
76

×
77
    // Literal
78
    let e = Expression::Literal(Field::Int(1337));
1✔
79
    assert_eq!(
1✔
80
        e.evaluate(&record, &schema)
1✔
81
            .unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
82
        Field::Int(1337)
1✔
83
    );
1✔
84

×
85
    // UnaryOperator
86
    let e = Expression::UnaryOperator {
1✔
87
        operator: UnaryOperatorType::Not,
1✔
88
        arg: Box::new(Expression::Literal(Field::Boolean(true))),
1✔
89
    };
1✔
90
    assert_eq!(
1✔
91
        e.evaluate(&record, &schema)
1✔
92
            .unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
93
        Field::Boolean(false)
1✔
94
    );
1✔
95

×
96
    // BinaryOperator
97
    let e = Expression::BinaryOperator {
1✔
98
        left: Box::new(Expression::Literal(Field::Boolean(true))),
1✔
99
        operator: BinaryOperatorType::And,
1✔
100
        right: Box::new(Expression::Literal(Field::Boolean(false))),
1✔
101
    };
1✔
102
    assert_eq!(
1✔
103
        e.evaluate(&record, &schema)
1✔
104
            .unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
105
        Field::Boolean(false),
1✔
106
    );
1✔
107

×
108
    // ScalarFunction
109
    let e = Expression::ScalarFunction {
1✔
110
        fun: ScalarFunctionType::Abs,
1✔
111
        args: vec![Expression::Literal(Field::Int(-1))],
1✔
112
    };
1✔
113
    assert_eq!(
1✔
114
        e.evaluate(&record, &schema)
1✔
115
            .unwrap_or_else(|e| panic!("{}", e.to_string())),
1✔
116
        Field::Int(1)
1✔
117
    );
1✔
118
}
1✔
119

×
120
#[test]
1✔
121
fn test_alias() {
1✔
122
    let schema = Schema::default()
1✔
123
        .field(
1✔
124
            FieldDefinition::new(
1✔
125
                String::from("fn"),
1✔
126
                FieldType::Text,
1✔
127
                false,
1✔
128
                SourceDefinition::Dynamic,
1✔
129
            ),
1✔
130
            false,
1✔
131
        )
1✔
132
        .field(
1✔
133
            FieldDefinition::new(
1✔
134
                String::from("ln"),
1✔
135
                FieldType::String,
1✔
136
                false,
1✔
137
                SourceDefinition::Dynamic,
1✔
138
            ),
1✔
139
            false,
1✔
140
        )
1✔
141
        .clone();
1✔
142

1✔
143
    let select = get_select("SELECT count(fn) AS alias1, ln as alias2 FROM t1").unwrap();
1✔
144
    let processor_factory =
1✔
145
        ProjectionProcessorFactory::_new("projection_id".to_owned(), select.projection);
1✔
146
    let r = processor_factory
1✔
147
        .get_output_schema(
1✔
148
            &DEFAULT_PORT_HANDLE,
1✔
149
            &[(DEFAULT_PORT_HANDLE, schema)].into_iter().collect(),
1✔
150
        )
1✔
151
        .unwrap();
1✔
152

1✔
153
    assert_eq!(
1✔
154
        r,
1✔
155
        Schema::default()
1✔
156
            .field(
1✔
157
                FieldDefinition::new(
1✔
158
                    String::from("alias1"),
1✔
159
                    FieldType::Text,
1✔
160
                    false,
1✔
161
                    SourceDefinition::Dynamic
1✔
162
                ),
1✔
163
                false,
1✔
164
            )
1✔
165
            .field(
1✔
166
                FieldDefinition::new(
1✔
167
                    String::from("alias2"),
1✔
168
                    FieldType::String,
1✔
169
                    false,
1✔
170
                    SourceDefinition::Dynamic
1✔
171
                ),
1✔
172
                false,
1✔
173
            )
1✔
174
            .clone()
1✔
175
    );
1✔
176
}
1✔
177

×
178
#[test]
1✔
179
fn test_wildcard() {
1✔
180
    let schema = Schema::default()
1✔
181
        .field(
1✔
182
            FieldDefinition::new(
1✔
183
                String::from("fn"),
1✔
184
                FieldType::Text,
1✔
185
                false,
1✔
186
                SourceDefinition::Dynamic,
1✔
187
            ),
1✔
188
            false,
1✔
189
        )
1✔
190
        .field(
1✔
191
            FieldDefinition::new(
1✔
192
                String::from("ln"),
1✔
193
                FieldType::String,
1✔
194
                false,
1✔
195
                SourceDefinition::Dynamic,
1✔
196
            ),
1✔
197
            false,
1✔
198
        )
1✔
199
        .clone();
1✔
200

1✔
201
    let select = get_select("SELECT * FROM t1").unwrap();
1✔
202
    let processor_factory =
1✔
203
        ProjectionProcessorFactory::_new("projection_id".to_owned(), select.projection);
1✔
204
    let r = processor_factory
1✔
205
        .get_output_schema(
1✔
206
            &DEFAULT_PORT_HANDLE,
1✔
207
            &[(DEFAULT_PORT_HANDLE, schema)].into_iter().collect(),
1✔
208
        )
1✔
209
        .unwrap();
1✔
210

1✔
211
    assert_eq!(
1✔
212
        r,
1✔
213
        Schema::default()
1✔
214
            .field(
1✔
215
                FieldDefinition::new(
1✔
216
                    String::from("fn"),
1✔
217
                    FieldType::Text,
1✔
218
                    false,
1✔
219
                    SourceDefinition::Dynamic
1✔
220
                ),
1✔
221
                false,
1✔
222
            )
1✔
223
            .field(
1✔
224
                FieldDefinition::new(
1✔
225
                    String::from("ln"),
1✔
226
                    FieldType::String,
1✔
227
                    false,
1✔
228
                    SourceDefinition::Dynamic
1✔
229
                ),
1✔
230
                false,
1✔
231
            )
1✔
232
            .clone()
1✔
233
    );
1✔
234
}
1✔
235

×
236
#[test]
1✔
237
fn test_timestamp_difference() {
1✔
238
    let schema = Schema::default()
1✔
239
        .field(
1✔
240
            FieldDefinition::new(
1✔
241
                String::from("a"),
1✔
242
                FieldType::Timestamp,
1✔
243
                false,
1✔
244
                SourceDefinition::Dynamic,
1✔
245
            ),
1✔
246
            true,
1✔
247
        )
1✔
248
        .field(
1✔
249
            FieldDefinition::new(
1✔
250
                String::from("b"),
1✔
251
                FieldType::Timestamp,
1✔
252
                false,
1✔
253
                SourceDefinition::Dynamic,
1✔
254
            ),
1✔
255
            false,
1✔
256
        )
1✔
257
        .clone();
1✔
258

1✔
259
    let record = Record::new(vec![
1✔
260
        Field::Timestamp(DateTime::parse_from_rfc3339("2020-01-01T00:13:00Z").unwrap()),
1✔
261
        Field::Timestamp(DateTime::parse_from_rfc3339("2020-01-01T00:12:10Z").unwrap()),
1✔
262
    ]);
1✔
263

1✔
264
    let result = evaluate_sub(
1✔
265
        &schema,
1✔
266
        &Expression::Column { index: 0 },
1✔
267
        &Expression::Column { index: 1 },
1✔
268
        &record,
1✔
269
    )
1✔
270
    .unwrap();
1✔
271
    assert_eq!(
1✔
272
        result,
1✔
273
        Field::Duration(DozerDuration(
1✔
274
            std::time::Duration::from_nanos(50000 * 1000 * 1000),
1✔
275
            TimeUnit::Nanoseconds
1✔
276
        ))
1✔
277
    );
1✔
278

×
279
    let result = evaluate_sub(
1✔
280
        &schema,
1✔
281
        &Expression::Column { index: 1 },
1✔
282
        &Expression::Column { index: 0 },
1✔
283
        &record,
1✔
284
    );
1✔
285
    assert!(result.is_err());
1✔
286
}
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