doki23 commented on a change in pull request #2068:
URL: https://github.com/apache/arrow-datafusion/pull/2068#discussion_r833893451
##########
File path: datafusion-physical-expr/src/expressions/case.rs
##########
@@ -323,24 +323,19 @@ impl CaseExpr {
let base_value = expr.evaluate(batch)?;
let base_type = expr.data_type(&batch.schema())?;
let base_value = base_value.into_array(batch.num_rows());
+ let base_nulls = is_null(base_value.as_ref())?;
- // start with the else condition, or nulls
- let mut current_value: Option<ArrayRef> = if let Some(e) =
&self.else_expr {
- // keep `else_expr`'s data type and return type consistent
- let expr = try_cast(e.clone(), &*batch.schema(),
return_type.clone())
- .unwrap_or_else(|_| e.clone());
- Some(expr.evaluate(batch)?.into_array(batch.num_rows()))
- } else {
- Some(new_null_array(&return_type, batch.num_rows()))
- };
-
- // walk backwards through the when/then expressions
- for i in (0..self.when_then_expr.len()).rev() {
+ // start with nulls as default output
+ let mut current_value = new_null_array(&return_type, batch.num_rows());
+ // We only consider non-null values while comparing with whens
+ let mut remainder = not(&base_nulls)?;
+ for i in 0..self.when_then_expr.len() {
let i = i as usize;
- let when_value = self.when_then_expr[i].0.evaluate(batch)?;
+ let when_value = self.when_then_expr[i]
+ .0
+ .evaluate_selection(batch, &remainder)?;
Review comment:
👍 Great! It's short-circuit now.
--
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]