-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: array_position nested lists handling & check index for nulls #21791
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -19,10 +19,12 @@ | |
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use arrow::compute::SortOptions; | ||
| use arrow::datatypes::{DataType, Field, Fields}; | ||
|
|
||
| use arrow::array::{ | ||
| Array, ArrayRef, BooleanArray, GenericListArray, OffsetSizeTrait, Scalar, | ||
| make_comparator, | ||
| }; | ||
| use arrow::buffer::OffsetBuffer; | ||
| use datafusion_common::cast::{ | ||
|
|
@@ -220,6 +222,30 @@ pub(crate) fn compare_element_to_list( | |
| Ok(res) | ||
| } | ||
|
|
||
| /// Given a `haystack` array, and a specific value from `needle` selected by | ||
| /// `needle_element_index`, return a `BooleanArray` based on whether the elements | ||
| /// in `haystack` match the `needle` value using `IS NOT DISTINCT FROM` semantics. | ||
| /// - Allows NULL = NULL to be considered true | ||
| pub(crate) fn compare_element_to_list_fixed<const IS_LIST: bool>( | ||
|
Contributor
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. I added a new version as I didn't want to affect (this is why I also omitted the |
||
| haystack: &dyn Array, | ||
| needle: &dyn Array, | ||
| needle_element_index: usize, | ||
| ) -> Result<BooleanArray> { | ||
| if IS_LIST { | ||
|
Contributor
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. I figured it would be a better idea to not do this datatype check inside, as this function is in the hotloop (called for every row), so pulled it into a const generic |
||
| // arrow_ord::cmp::eq does not support ListArray, so we resort to make_comparator | ||
| let cmp = make_comparator(haystack, needle, SortOptions::default())?; | ||
| let res = (0..haystack.len()) | ||
| .map(|i| cmp(i, needle_element_index).is_eq()) | ||
| .collect::<BooleanArray>(); | ||
| Ok(res) | ||
|
Contributor
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. Main fix here, using comparator now which handles nulls on both sides properly (null = null is true) |
||
| } else { | ||
| let needle = needle.slice(needle_element_index, 1); | ||
| let needle_value = Scalar::new(needle); | ||
| // use not_distinct so we can compare NULL | ||
| Ok(arrow_ord::cmp::not_distinct(&haystack, &needle_value)?) | ||
| } | ||
| } | ||
|
|
||
| /// Returns the length of each array dimension | ||
| pub(crate) fn compute_array_dims( | ||
| arr: Option<ArrayRef>, | ||
|
|
||
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.
Technically this was checked by the below arm, but I added this as a more specific error message