Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion dozer-sql/expression/src/in_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ pub(crate) fn evaluate_in_list(
record: &Record,
) -> Result<Field, Error> {
let field = expr.evaluate(record, schema)?;
if field == Field::Null {
return Ok(Field::Null);
}
let mut result = false;
let mut has_null = false;
for item in list {
let item = item.evaluate(record, schema)?;
if field == item {
if item == Field::Null {
has_null = true;
} else if field == item {
result = true;
break;
}
}
if !result && has_null {
return Ok(Field::Null);
}
// Negate the result if the IN list was negated.
if negated {
result = !result;
Expand Down
32 changes: 32 additions & 0 deletions dozer-sql/src/expression/tests/in_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,35 @@ fn test_not_in_list() {
);
assert_eq!(f, Field::Boolean(false));
}


#[test]
fn test_in_list_null_semantics() {
let f = run_fct(
"SELECT NULL IN (1, 2, 3)",
Schema::default(),
vec![],
);
assert_eq!(f, Field::Null);

let f = run_fct(
"SELECT 42 IN (1, 2, NULL)",
Schema::default(),
vec![],
);
assert_eq!(f, Field::Null);

let f = run_fct(
"SELECT 42 NOT IN (1, 2, NULL)",
Schema::default(),
vec![],
);
assert_eq!(f, Field::Null);

let f = run_fct(
"SELECT 42 IN (1, 2, 42, NULL)",
Schema::default(),
vec![],
);
assert_eq!(f, Field::Boolean(true));
}