@@ -345,34 +345,37 @@ impl CaseExpr {
345345 let when_expr = & self . when_then_expr [ 0 ] . 0 ;
346346 let then_expr = & self . when_then_expr [ 0 ] . 1 ;
347347
348- let when_expr_value = when_expr. evaluate ( batch) ?;
349- let when_expr_value = match when_expr_value {
348+ match when_expr. evaluate ( batch) ? {
349+ // WHEN true --> column
350+ ColumnarValue :: Scalar ( ScalarValue :: Boolean ( Some ( true ) ) ) => {
351+ then_expr. evaluate ( batch)
352+ }
353+ // WHEN [false | null] --> NULL
350354 ColumnarValue :: Scalar ( _) => {
351- ColumnarValue :: Array ( when_expr_value. into_array ( batch. num_rows ( ) ) ?)
355+ // return scalar NULL value
356+ ScalarValue :: try_from ( self . data_type ( & batch. schema ( ) ) ?)
357+ . map ( ColumnarValue :: Scalar )
352358 }
353- other => other,
354- } ;
355-
356- if let ColumnarValue :: Array ( bit_mask) = when_expr_value {
357- let bit_mask = bit_mask
358- . as_any ( )
359- . downcast_ref :: < BooleanArray > ( )
360- . expect ( "predicate should evaluate to a boolean array" ) ;
361- // invert the bitmask
362- let bit_mask = match bit_mask. null_count ( ) {
363- 0 => not ( bit_mask) ?,
364- _ => not ( & prep_null_mask_filter ( bit_mask) ) ?,
365- } ;
366- match then_expr. evaluate ( batch) ? {
367- ColumnarValue :: Array ( array) => {
368- Ok ( ColumnarValue :: Array ( nullif ( & array, & bit_mask) ?) )
369- }
370- ColumnarValue :: Scalar ( _) => {
371- internal_err ! ( "expression did not evaluate to an array" )
359+ // WHEN column --> column
360+ ColumnarValue :: Array ( bit_mask) => {
361+ let bit_mask = bit_mask
362+ . as_any ( )
363+ . downcast_ref :: < BooleanArray > ( )
364+ . expect ( "predicate should evaluate to a boolean array" ) ;
365+ // invert the bitmask
366+ let bit_mask = match bit_mask. null_count ( ) {
367+ 0 => not ( bit_mask) ?,
368+ _ => not ( & prep_null_mask_filter ( bit_mask) ) ?,
369+ } ;
370+ match then_expr. evaluate ( batch) ? {
371+ ColumnarValue :: Array ( array) => {
372+ Ok ( ColumnarValue :: Array ( nullif ( & array, & bit_mask) ?) )
373+ }
374+ ColumnarValue :: Scalar ( _) => {
375+ internal_err ! ( "expression did not evaluate to an array" )
376+ }
372377 }
373378 }
374- } else {
375- internal_err ! ( "predicate did not evaluate to an array" )
376379 }
377380 }
378381
0 commit comments