@@ -75,7 +75,7 @@ use arrow::record_batch::RecordBatch;
7575
7676use crate :: physical_expr:: down_cast_any_ref;
7777use crate :: { AnalysisContext , ExprBoundaries , PhysicalExpr } ;
78- use datafusion_common:: cast:: as_decimal128_array;
78+ use datafusion_common:: cast:: { as_boolean_array , as_decimal128_array} ;
7979use datafusion_common:: ScalarValue ;
8080use datafusion_common:: { DataFusionError , Result } ;
8181use datafusion_expr:: type_coercion:: binary:: binary_operator_data_type;
@@ -472,14 +472,8 @@ macro_rules! binary_array_op {
472472/// Invoke a boolean kernel on a pair of arrays
473473macro_rules! boolean_op {
474474 ( $LEFT: expr, $RIGHT: expr, $OP: ident) => { {
475- let ll = $LEFT
476- . as_any( )
477- . downcast_ref:: <BooleanArray >( )
478- . expect( "boolean_op failed to downcast array" ) ;
479- let rr = $RIGHT
480- . as_any( )
481- . downcast_ref:: <BooleanArray >( )
482- . expect( "boolean_op failed to downcast array" ) ;
475+ let ll = as_boolean_array( $LEFT) . expect( "boolean_op failed to downcast array" ) ;
476+ let rr = as_boolean_array( $RIGHT) . expect( "boolean_op failed to downcast array" ) ;
483477 Ok ( Arc :: new( $OP( & ll, & rr) ?) )
484478 } } ;
485479}
@@ -1003,7 +997,7 @@ impl BinaryExpr {
1003997 Operator :: Modulo => binary_primitive_array_op ! ( left, right, modulus) ,
1004998 Operator :: And => {
1005999 if left_data_type == & DataType :: Boolean {
1006- boolean_op ! ( left, right, and_kleene)
1000+ boolean_op ! ( & left, & right, and_kleene)
10071001 } else {
10081002 Err ( DataFusionError :: Internal ( format ! (
10091003 "Cannot evaluate binary expression {:?} with types {:?} and {:?}" ,
@@ -1015,7 +1009,7 @@ impl BinaryExpr {
10151009 }
10161010 Operator :: Or => {
10171011 if left_data_type == & DataType :: Boolean {
1018- boolean_op ! ( left, right, or_kleene)
1012+ boolean_op ! ( & left, & right, or_kleene)
10191013 } else {
10201014 Err ( DataFusionError :: Internal ( format ! (
10211015 "Cannot evaluate binary expression {:?} with types {:?} and {:?}" ,
@@ -1110,10 +1104,8 @@ mod tests {
11101104 assert_eq ! ( result. len( ) , 5 ) ;
11111105
11121106 let expected = vec ! [ false , false , true , true , true ] ;
1113- let result = result
1114- . as_any ( )
1115- . downcast_ref :: < BooleanArray > ( )
1116- . expect ( "failed to downcast to BooleanArray" ) ;
1107+ let result =
1108+ as_boolean_array ( & result) . expect ( "failed to downcast to BooleanArray" ) ;
11171109 for ( i, & expected_item) in expected. iter ( ) . enumerate ( ) . take ( 5 ) {
11181110 assert_eq ! ( result. value( i) , expected_item) ;
11191111 }
@@ -1156,10 +1148,8 @@ mod tests {
11561148 assert_eq ! ( result. len( ) , 5 ) ;
11571149
11581150 let expected = vec ! [ true , true , false , true , false ] ;
1159- let result = result
1160- . as_any ( )
1161- . downcast_ref :: < BooleanArray > ( )
1162- . expect ( "failed to downcast to BooleanArray" ) ;
1151+ let result =
1152+ as_boolean_array ( & result) . expect ( "failed to downcast to BooleanArray" ) ;
11631153 for ( i, & expected_item) in expected. iter ( ) . enumerate ( ) . take ( 5 ) {
11641154 assert_eq ! ( result. value( i) , expected_item) ;
11651155 }
0 commit comments