From f1087f5c042ea093c6fd4d700dcecd8d2da6bf4a Mon Sep 17 00:00:00 2001 From: Yevhenii Melnyk Date: Thu, 2 Feb 2023 10:38:52 +0100 Subject: [PATCH] Compare NULL types --- .../pg_compat/pg_compat_type_coercion.slt | 13 +++++-------- datafusion/expr/src/type_coercion/binary.rs | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) 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 aee35e08f59f1..4a85a835c0790 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 d2923c8dbfae7..08e0aac251ea6 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) } @@ -1147,13 +1147,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,