You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/07 02:18:32 UTC

[GitHub] [arrow-datafusion] yjshen commented on a diff in pull request #2171: minor: Avoid per cell evaluation in Coalesce, use zip in CaseWhen

yjshen commented on code in PR #2171:
URL: https://github.com/apache/arrow-datafusion/pull/2171#discussion_r844576185


##########
datafusion/physical-expr/src/conditional_expressions.rs:
##########
@@ -35,36 +33,51 @@ pub fn coalesce(args: &[ColumnarValue]) -> Result<ColumnarValue> {
         )));
     }
 
-    let size = match args[0] {
-        ColumnarValue::Array(ref a) => a.len(),
-        ColumnarValue::Scalar(ref _s) => 1,
-    };
-    let mut res = new_null_array(&args[0].data_type(), size);
+    let return_type = args[0].data_type();
+    let mut return_array = args.iter().filter_map(|x| match x {
+        ColumnarValue::Array(array) => Some(array.len()),
+        _ => None,

Review Comment:
   return_array is used to decide whether to return a scalar or a vector, so if we see no array sizes and get None from `return_array.next()` we know all params are scalar and will enter branch in line-70 and do fast scalar value coalesce.



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org