-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add IS NULL expression (#2468)
- Loading branch information
1 parent
529182a
commit f155736
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use dozer_types::types::Record; | ||
use dozer_types::types::{Field, Schema}; | ||
|
||
use crate::error::Error; | ||
use crate::execution::Expression; | ||
|
||
pub(crate) fn evaluate_is_null( | ||
schema: &Schema, | ||
expr: &mut Expression, | ||
record: &Record, | ||
) -> Result<Field, Error> { | ||
let field = expr.evaluate(record, schema)?; | ||
Ok(Field::Boolean(field == Field::Null)) | ||
} | ||
|
||
pub(crate) fn evaluate_is_not_null( | ||
schema: &Schema, | ||
expr: &mut Expression, | ||
record: &Record, | ||
) -> Result<Field, Error> { | ||
let field = expr.evaluate(record, schema)?; | ||
Ok(Field::Boolean(field != Field::Null)) | ||
} | ||
|
||
#[test] | ||
fn test_is_null() { | ||
let mut value = Box::new(Expression::Literal(Field::Int(65))); | ||
assert_eq!( | ||
evaluate_is_null(&Schema::default(), &mut value, &Record::new(vec![])).unwrap(), | ||
Field::Boolean(false) | ||
); | ||
|
||
let mut value = Box::new(Expression::Literal(Field::Null)); | ||
assert_eq!( | ||
evaluate_is_null(&Schema::default(), &mut value, &Record::new(vec![])).unwrap(), | ||
Field::Boolean(true) | ||
); | ||
|
||
let mut value = Box::new(Expression::Literal(Field::Int(65))); | ||
assert_eq!( | ||
evaluate_is_not_null(&Schema::default(), &mut value, &Record::new(vec![])).unwrap(), | ||
Field::Boolean(true) | ||
); | ||
|
||
let mut value = Box::new(Expression::Literal(Field::Null)); | ||
assert_eq!( | ||
evaluate_is_not_null(&Schema::default(), &mut value, &Record::new(vec![])).unwrap(), | ||
Field::Boolean(false) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters