@@ -793,17 +793,13 @@ impl CaseBody {
793793 }
794794 } ?;
795795
796- // `true_count` ignores `true` values where the validity bit is not set, so there's
797- // no need to call `prep_null_mask_filter`.
798- let when_true_count = when_value. true_count ( ) ;
799-
800796 // If the 'when' predicate did not match any rows, continue to the next branch immediately
801- if when_true_count == 0 {
797+ if !when_value . has_true ( ) {
802798 continue ;
803799 }
804800
805801 // If the 'when' predicate matched all remaining rows, there is no need to filter
806- if when_true_count == remainder_batch . num_rows ( ) {
802+ if when_value . null_count ( ) == 0 && !when_value . has_false ( ) {
807803 let then_expression = & self . when_then_expr [ i] . 1 ;
808804 let then_value = then_expression. evaluate ( & remainder_batch) ?;
809805 result_builder. add_branch_result ( & remainder_rows, then_value) ?;
@@ -882,17 +878,13 @@ impl CaseBody {
882878 internal_datafusion_err ! ( "WHEN expression did not return a BooleanArray" )
883879 } ) ?;
884880
885- // `true_count` ignores `true` values where the validity bit is not set, so there's
886- // no need to call `prep_null_mask_filter`.
887- let when_true_count = when_value. true_count ( ) ;
888-
889881 // If the 'when' predicate did not match any rows, continue to the next branch immediately
890- if when_true_count == 0 {
882+ if !when_value . has_true ( ) {
891883 continue ;
892884 }
893885
894886 // If the 'when' predicate matched all remaining rows, there is no need to filter
895- if when_true_count == remainder_batch . num_rows ( ) {
887+ if when_value . null_count ( ) == 0 && !when_value . has_false ( ) {
896888 let then_expression = & self . when_then_expr [ i] . 1 ;
897889 let then_value = then_expression. evaluate ( & remainder_batch) ?;
898890 result_builder. add_branch_result ( & remainder_rows, then_value) ?;
@@ -1144,11 +1136,10 @@ impl CaseExpr {
11441136 )
11451137 } ) ?;
11461138
1147- let true_count = when_value. true_count ( ) ;
1148- if true_count == when_value. len ( ) {
1139+ if when_value. null_count ( ) == 0 && !when_value. has_false ( ) {
11491140 // All input rows are true, just call the 'then' expression
11501141 self . body . when_then_expr [ 0 ] . 1 . evaluate ( batch)
1151- } else if true_count == 0 {
1142+ } else if !when_value . has_true ( ) {
11521143 // All input rows are false/null, just call the 'else' expression
11531144 match & self . body . else_expr {
11541145 Some ( else_expr) => else_expr. evaluate ( batch) ,
0 commit comments