rluvaton commented on code in PR #23923:
URL: https://github.com/apache/datafusion/pull/23923#discussion_r3658638564


##########
datafusion/functions-nested/src/empty.rs:
##########
@@ -122,9 +122,17 @@ fn array_empty_inner(args: &[ArrayRef]) -> 
Result<ArrayRef> {
 }
 
 fn general_array_empty<O: OffsetSizeTrait>(array: &ArrayRef) -> 
Result<ArrayRef> {
-    let result = as_generic_list_array::<O>(array)?
-        .iter()
-        .map(|arr| arr.map(|arr| arr.is_empty()))
-        .collect::<BooleanArray>();
+    let result = as_generic_list_array::<O>(array)?;
+    // No nulls, just look at the offsets
+    let is_empty_iter = result.offsets().lengths().map(|n| n == 0);
+    // SAFETY: this is safe since the iterator lengths is exact size and
+    // trusted - it maps over fixed known number of elements
+    let output_buffer = unsafe { 
BooleanArray::from_trusted_len_iter(is_empty_iter) };
+
+    let (values, _) = output_buffer.into_parts();
+
+    // Add the nulls
+    let result = BooleanArray::new(values, result.nulls().filter(|n| 
n.null_count() > 0).cloned());

Review Comment:
   We don't need to evaluate the null of specific items since they are not 
relevant, we just need to move them



-- 
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]

Reply via email to