@@ -496,6 +496,7 @@ pub fn comparison_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
496496 return Some ( lhs_type. clone ( ) ) ;
497497 }
498498 binary_numeric_coercion ( lhs_type, rhs_type)
499+ . or_else ( || number_boolean_coercion ( lhs_type, rhs_type) )
499500 . or_else ( || dictionary_comparison_coercion ( lhs_type, rhs_type, true ) )
500501 . or_else ( || temporal_coercion_nonstrict_timezone ( lhs_type, rhs_type) )
501502 . or_else ( || string_coercion ( lhs_type, rhs_type) )
@@ -524,6 +525,16 @@ pub fn values_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataT
524525 . or_else ( || binary_coercion ( lhs_type, rhs_type) )
525526}
526527
528+ /// Coerce `lhs_type` and `rhs_type` to Boolean when doing a number-vs.-bool comparison.
529+ fn number_boolean_coercion ( lhs_type : & DataType , rhs_type : & DataType ) -> Option < DataType > {
530+ use arrow:: datatypes:: DataType :: * ;
531+ match ( lhs_type, rhs_type) {
532+ ( Boolean , _) if rhs_type. is_numeric ( ) => Some ( Boolean ) ,
533+ ( _, Boolean ) if lhs_type. is_numeric ( ) => Some ( Boolean ) ,
534+ _ => None ,
535+ }
536+ }
537+
527538/// Coerce `lhs_type` and `rhs_type` to a common type for the purposes of a comparison operation
528539/// where one is numeric and one is `Utf8`/`LargeUtf8`.
529540fn string_numeric_coercion ( lhs_type : & DataType , rhs_type : & DataType ) -> Option < DataType > {
0 commit comments