@@ -734,6 +734,7 @@ pub fn comparison_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
734734 . or_else ( || binary_coercion ( lhs_type, rhs_type) )
735735 . or_else ( || struct_coercion ( lhs_type, rhs_type) )
736736 . or_else ( || map_coercion ( lhs_type, rhs_type) )
737+ . or_else ( || boolean_coercion ( lhs_type, rhs_type) )
737738}
738739
739740/// Similar to [`comparison_coercion`] but prefers numeric if compares with
@@ -1007,6 +1008,20 @@ fn map_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
10071008 }
10081009}
10091010
1011+ /// Coercion rules for boolean types: If at least one argument is
1012+ /// a boolean type and both arguments can be coerced into a boolean type, coerce
1013+ /// to boolean type.
1014+ fn boolean_coercion ( lhs_type : & DataType , rhs_type : & DataType ) -> Option < DataType > {
1015+ use arrow:: datatypes:: DataType :: * ;
1016+ match ( lhs_type, rhs_type) {
1017+ ( Boolean , Int8 | Int16 | Int32 | Int64 | UInt8 | UInt16 | UInt32 | UInt64 )
1018+ | ( Int8 | Int16 | Int32 | Int64 | UInt8 | UInt16 | UInt32 | UInt64 , Boolean ) => {
1019+ Some ( Boolean )
1020+ }
1021+ _ => None ,
1022+ }
1023+ }
1024+
10101025/// Returns the output type of applying mathematics operations such as
10111026/// `+` to arguments of `lhs_type` and `rhs_type`.
10121027fn mathematics_numerical_coercion (
@@ -2434,6 +2449,32 @@ mod tests {
24342449 DataType :: List ( Arc :: clone( & inner_field) )
24352450 ) ;
24362451
2452+ // boolean
2453+ let int_types = vec ! [
2454+ DataType :: Int8 ,
2455+ DataType :: Int16 ,
2456+ DataType :: Int32 ,
2457+ DataType :: Int64 ,
2458+ DataType :: UInt8 ,
2459+ DataType :: UInt16 ,
2460+ DataType :: UInt32 ,
2461+ DataType :: UInt64 ,
2462+ ] ;
2463+ for int_type in int_types {
2464+ test_coercion_binary_rule ! (
2465+ DataType :: Boolean ,
2466+ int_type,
2467+ Operator :: Eq ,
2468+ DataType :: Boolean
2469+ ) ;
2470+ test_coercion_binary_rule ! (
2471+ int_type,
2472+ DataType :: Boolean ,
2473+ Operator :: Eq ,
2474+ DataType :: Boolean
2475+ ) ;
2476+ }
2477+
24372478 // Negative test: inner_timestamp_field and inner_field are not compatible because their inner types are not compatible
24382479 let inner_timestamp_field = Arc :: new ( Field :: new_list_field (
24392480 DataType :: Timestamp ( TimeUnit :: Microsecond , None ) ,
0 commit comments