Skip to content
Merged
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
42 changes: 41 additions & 1 deletion datafusion/expr/src/type_coercion/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ pub fn coerce_types(
| Operator::BitwiseShiftRight
| Operator::BitwiseShiftLeft => bitwise_coercion(lhs_type, rhs_type),
Operator::And | Operator::Or => match (lhs_type, rhs_type) {
// logical binary boolean operators can only be evaluated in bools
// logical binary boolean operators can only be evaluated in bools or nulls
(DataType::Boolean, DataType::Boolean) => Some(DataType::Boolean),
(DataType::Null, DataType::Null) => Some(DataType::Null),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

(DataType::Boolean, DataType::Null) | (DataType::Null, DataType::Boolean) => {
Some(DataType::Boolean)
}
_ => None,
},
// logical comparison operators have their own rules, and always return a boolean
Expand Down Expand Up @@ -1022,6 +1026,42 @@ mod tests {
Operator::Or,
DataType::Boolean
);
test_coercion_binary_rule!(
DataType::Boolean,
DataType::Null,
Operator::And,
DataType::Boolean
);
test_coercion_binary_rule!(
DataType::Boolean,
DataType::Null,
Operator::Or,
DataType::Boolean
);
test_coercion_binary_rule!(
DataType::Null,
DataType::Null,
Operator::Or,
DataType::Null
);
test_coercion_binary_rule!(
DataType::Null,
DataType::Null,
Operator::And,
DataType::Null
);
test_coercion_binary_rule!(
DataType::Null,
DataType::Boolean,
Operator::And,
DataType::Boolean
);
test_coercion_binary_rule!(
DataType::Null,
DataType::Boolean,
Operator::Or,
DataType::Boolean
);
Ok(())
}
}