andygrove commented on code in PR #11534:
URL: https://github.com/apache/datafusion/pull/11534#discussion_r1683559603
##########
datafusion/physical-expr/src/expressions/case.rs:
##########
@@ -86,13 +108,35 @@ impl CaseExpr {
when_then_expr: Vec<WhenThen>,
else_expr: Option<Arc<dyn PhysicalExpr>>,
) -> Result<Self> {
+ // normalize null literals to None in the else_expr (this already
happens
+ // during SQL planning, but not necessarily for other use cases)
+ let else_expr = match &else_expr {
+ Some(e) => match e.as_any().downcast_ref::<Literal>() {
+ Some(lit) if lit.value().is_null() => None,
+ _ => else_expr,
+ },
+ _ => else_expr,
+ };
+
if when_then_expr.is_empty() {
exec_err!("There must be at least one WHEN clause")
} else {
+ let eval_method = if expr.is_some() {
+ EvalMethod::WithExpression
+ } else if when_then_expr.len() == 1
Review Comment:
Generally, it is only safe to use this approach for expressions that are
infallible. One of the main reasons that regular CaseExpr is expensive is that
we need to only evaluate the "true" expression on rows where the predicate has
evaluated to true.
I do think that this could be extended beyond just Column expressions though.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]