-
Notifications
You must be signed in to change notification settings - Fork 2.3k
perf: optimize array_empty udf
#23923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,9 +122,19 @@ 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())) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| .collect::<BooleanArray>(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. collect not using the |
||
| let result = as_generic_list_array::<O>(array)?; | ||
| let is_empty_iter = result.offsets().lengths().map(|n| n == 0); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is faster since we only need to look at one buffer and can make it very fast |
||
| // 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(), | ||
| ); | ||
|
|
||
| Ok(Arc::new(result)) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling
iteronListArrayis slow since it slice each list values which every slice recompute the null count and more