Skip to content

Apache DataFusion SQL Query Engine

Compare NULL types (#5158)

Yevhenii Melnyk7d2d51b651d0
diff --git a/datafusion/core/tests/sqllogictests/test_files/pg_compat/pg_compat_type_coercion.slt b/datafusion/core/tests/sqllogictests/test_files/pg_compat/pg_compat_type_coercion.slt
index aee35e08f5..4a85a835c0 100644
--- a/datafusion/core/tests/sqllogictests/test_files/pg_compat/pg_compat_type_coercion.slt
+++ b/datafusion/core/tests/sqllogictests/test_files/pg_compat/pg_compat_type_coercion.slt
@@ -95,20 +95,17 @@ select pg_typeof(false or true), pg_typeof(true or false);
bool bool
-# TODO: run for DataFusion as well after #4335
-onlyif postgres
query ??
select null and null, null or null;
----
NULL NULL
-# TODO: uncomment after #4335
-#onlyif DataFusion
-#query ??
-#select arrow_typeof(null and null), arrow_typeof(null or null);
-#----
-#Boolean Boolean
+onlyif DataFusion
+query ??
+select arrow_typeof(null and null), arrow_typeof(null or null);
+----
+Boolean Boolean
onlyif postgres
diff --git a/datafusion/expr/src/type_coercion/binary.rs b/datafusion/expr/src/type_coercion/binary.rs
index d942d1cf1c..000011f9d6 100644
--- a/datafusion/expr/src/type_coercion/binary.rs
+++ b/datafusion/expr/src/type_coercion/binary.rs
@@ -100,7 +100,7 @@ pub fn coerce_types(
Operator::And | Operator::Or => match (lhs_type, rhs_type) {
// 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),
+ (DataType::Null, DataType::Null) => Some(DataType::Boolean),
(DataType::Boolean, DataType::Null) | (DataType::Null, DataType::Boolean) => {
Some(DataType::Boolean)
}
@@ -1144,13 +1144,13 @@ mod tests {
DataType::Null,
DataType::Null,
Operator::Or,
- DataType::Null
+ DataType::Boolean
);
test_coercion_binary_rule!(
DataType::Null,
DataType::Null,
Operator::And,
- DataType::Null
+ DataType::Boolean
);
test_coercion_binary_rule!(
DataType::Null,