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

getdozer / dozer / 5709656380

pending completion
5709656380

push

github

web-flow
Version bump (#1808)

45512 of 59772 relevant lines covered (76.14%)

39312.43 hits per line

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

66.67
/dozer-sql/src/pipeline/expression/conditional.rs
1
use crate::pipeline::errors::PipelineError;
2
use crate::pipeline::errors::PipelineError::{InvalidFunction, NotEnoughArguments};
3
use crate::pipeline::expression::execution::{Expression, ExpressionType};
4
use dozer_core::processor_record::ProcessorRecord;
5
use dozer_types::types::{Field, FieldType, Schema};
6
use std::fmt::{Display, Formatter};
7

8
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
5✔
9
pub enum ConditionalExpressionType {
10
    Coalesce,
×
11
    NullIf,
12
}
13

14
pub(crate) fn get_conditional_expr_type(
5✔
15
    function: &ConditionalExpressionType,
5✔
16
    args: &[Expression],
5✔
17
    schema: &Schema,
5✔
18
) -> Result<ExpressionType, PipelineError> {
5✔
19
    match function {
5✔
20
        ConditionalExpressionType::Coalesce => validate_coalesce(args, schema),
5✔
21
        ConditionalExpressionType::NullIf => todo!(),
×
22
    }
×
23
}
5✔
24

25
impl ConditionalExpressionType {
×
26
    pub(crate) fn new(name: &str) -> Result<ConditionalExpressionType, PipelineError> {
42✔
27
        match name {
42✔
28
            "coalesce" => Ok(ConditionalExpressionType::Coalesce),
42✔
29
            "nullif" => Ok(ConditionalExpressionType::NullIf),
32✔
30
            _ => Err(InvalidFunction(name.to_string())),
32✔
31
        }
×
32
    }
42✔
33

34
    pub(crate) fn evaluate(
5✔
35
        &self,
5✔
36
        schema: &Schema,
5✔
37
        args: &[Expression],
5✔
38
        record: &ProcessorRecord,
5✔
39
    ) -> Result<Field, PipelineError> {
5✔
40
        match self {
5✔
41
            ConditionalExpressionType::Coalesce => evaluate_coalesce(schema, args, record),
5✔
42
            ConditionalExpressionType::NullIf => todo!(),
×
43
        }
×
44
    }
5✔
45
}
46

×
47
pub(crate) fn validate_coalesce(
34,005✔
48
    args: &[Expression],
34,005✔
49
    schema: &Schema,
34,005✔
50
) -> Result<ExpressionType, PipelineError> {
34,005✔
51
    if args.is_empty() {
34,005✔
52
        return Err(NotEnoughArguments(
×
53
            ConditionalExpressionType::Coalesce.to_string(),
×
54
        ));
×
55
    }
34,005✔
56

34,005✔
57
    let return_types = args
34,005✔
58
        .iter()
34,005✔
59
        .map(|expr| expr.get_type(schema).unwrap().return_type)
107,009✔
60
        .collect::<Vec<FieldType>>();
34,005✔
61
    let return_type = return_types[0];
34,005✔
62

34,005✔
63
    Ok(ExpressionType::new(
34,005✔
64
        return_type,
34,005✔
65
        false,
34,005✔
66
        dozer_types::types::SourceDefinition::Dynamic,
34,005✔
67
        false,
34,005✔
68
    ))
34,005✔
69
}
34,005✔
70

×
71
pub(crate) fn evaluate_coalesce(
34,005✔
72
    schema: &Schema,
34,005✔
73
    args: &[Expression],
34,005✔
74
    record: &ProcessorRecord,
34,005✔
75
) -> Result<Field, PipelineError> {
34,005✔
76
    // The COALESCE function returns the first of its arguments that is not null.
×
77
    for expr in args {
37,010✔
78
        let field = expr.evaluate(record, schema)?;
35,009✔
79
        if field != Field::Null {
35,009✔
80
            return Ok(field);
32,004✔
81
        }
3,005✔
82
    }
×
83
    // Null is returned only if all arguments are null.
×
84
    Ok(Field::Null)
2,001✔
85
}
34,005✔
86

×
87
impl Display for ConditionalExpressionType {
×
88
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
×
89
        match self {
×
90
            ConditionalExpressionType::Coalesce => f.write_str("COALESCE"),
×
91
            ConditionalExpressionType::NullIf => f.write_str("NULLIF"),
×
92
        }
×
93
    }
×
94
}
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