@@ -346,7 +346,7 @@ impl CaseExpr {
346346 . downcast_ref :: < BooleanArray > ( )
347347 . expect ( "predicate should evaluate to a boolean array" ) ;
348348 // invert the bitmask
349- let bit_mask = not ( bit_mask) ?;
349+ let bit_mask = not ( & prep_null_mask_filter ( & bit_mask) ) ?;
350350 match then_expr. evaluate ( batch) ? {
351351 ColumnarValue :: Array ( array) => {
352352 Ok ( ColumnarValue :: Array ( nullif ( & array, & bit_mask) ?) )
@@ -885,6 +885,32 @@ mod tests {
885885 Ok ( ( ) )
886886 }
887887
888+ #[ test]
889+ fn test_when_null_and_some_cond_else_null ( ) -> Result < ( ) > {
890+ let batch = case_test_batch ( ) ?;
891+ let schema = batch. schema ( ) ;
892+
893+ let when = binary (
894+ Arc :: new ( Literal :: new ( ScalarValue :: Boolean ( None ) ) ) ,
895+ Operator :: And ,
896+ binary ( col ( "a" , & schema) ?, Operator :: Eq , lit ( "foo" ) , & schema) ?,
897+ & schema,
898+ ) ?;
899+ let then = col ( "a" , & schema) ?;
900+
901+ // SELECT CASE WHEN (NULL AND a = 'foo') THEN a ELSE NULL END
902+ let expr = Arc :: new ( CaseExpr :: try_new ( None , vec ! [ ( when, then) ] , None ) ?) ;
903+ let result = expr
904+ . evaluate ( & batch) ?
905+ . into_array ( batch. num_rows ( ) )
906+ . expect ( "Failed to convert to array" ) ;
907+ let result = as_string_array ( & result) ;
908+
909+ // all result values should be null
910+ assert_eq ! ( result. logical_null_count( ) , batch. num_rows( ) ) ;
911+ Ok ( ( ) )
912+ }
913+
888914 fn case_test_batch ( ) -> Result < RecordBatch > {
889915 let schema = Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Utf8 , true ) ] ) ;
890916 let a = StringArray :: from ( vec ! [ Some ( "foo" ) , Some ( "baz" ) , None , Some ( "bar" ) ] ) ;
0 commit comments