alamb commented on code in PR #14156: URL: https://github.com/apache/datafusion/pull/14156#discussion_r1919254809
########## datafusion/physical-expr/src/expressions/case.rs: ########## @@ -344,7 +344,16 @@ impl CaseExpr { fn case_column_or_null(&self, batch: &RecordBatch) -> Result<ColumnarValue> { let when_expr = &self.when_then_expr[0].0; let then_expr = &self.when_then_expr[0].1; - if let ColumnarValue::Array(bit_mask) = when_expr.evaluate(batch)? { + + let when_expr_value = when_expr.evaluate(batch)?; + let when_expr_value = match when_expr_value { Review Comment: this is correct, but it effectively expands out the array even when the argument is a constant. We can probably make it more efficient by handling the other case too ########## datafusion/physical-expr/src/expressions/case.rs: ########## @@ -896,6 +905,53 @@ mod tests { Ok(()) } + #[test] + fn case_with_scalar_predicate() -> Result<()> { Review Comment: I personally recommend adding a .slt test for this in addition (and possibly also instead): ```diff --- a/datafusion/sqllogictest/test_files/case.slt +++ b/datafusion/sqllogictest/test_files/case.slt @@ -235,3 +235,10 @@ SELECT CASE WHEN a < 5 THEN a + b ELSE b - NVL(a, 0) END FROM foo NULL NULL 7 + +# Reproducer for +# https://github.com/apache/datafusion/issues/14099 +query I +SELECT - 79 * + 91 * - COUNT ( * ) * + - 2 * + - NULLIF ( - 49, - COALESCE ( - + 69, - COALESCE ( + COALESCE ( - 20, ( - 18 ) * + COUNT ( * ) + - 93, - CASE 51 WHEN + COUNT ( * ) + 28 THEN 0 ELSE + 29 * + CASE ( 50 ) WHEN - ( - ( CASE WHEN NOT + 37 IS NULL THEN + COUNT ( * ) END ) ) THEN NULL WHEN - 46 + 87 * - 28 THEN 85 WHEN - COUNT ( * ) THEN NULL END END ), COUNT ( * ) - 39 ) * + 22 ) / - COUNT ( * ) ) +---- +-704522 ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org