Skip to content
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

Improve default implementation of Array::is_nullable #6721

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions arrow-array/src/array/dictionary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,26 @@ impl<T: ArrowDictionaryKeyType> Array for DictionaryArray<T> {
}
}

fn logical_null_count(&self) -> usize {
match (self.keys.nulls(), self.values.logical_nulls()) {
(None, None) => 0,
(Some(key_nulls), None) => key_nulls.null_count(),
(None, Some(value_nulls)) => self
.keys
.values()
.iter()
.filter(|k| value_nulls.is_null(k.as_usize()))
.count(),
(Some(key_nulls), Some(value_nulls)) => self
.keys
.values()
.iter()
.enumerate()
.filter(|(idx, k)| key_nulls.is_null(*idx) || value_nulls.is_null(k.as_usize()))
.count(),
}
}

fn is_nullable(&self) -> bool {
!self.is_empty() && (self.nulls().is_some() || self.values.is_nullable())
}
Expand Down
3 changes: 1 addition & 2 deletions arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ pub trait Array: std::fmt::Debug + Send + Sync {
/// even if the nulls present in [`DictionaryArray::values`] are not referenced by any key,
/// and therefore would not appear in [`Array::logical_nulls`].
fn is_nullable(&self) -> bool {
// TODO this is not necessarily perfect default implementation, since null_count() and logical_null_count() are not always equivalent
self.null_count() != 0
self.logical_null_count() != 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we provide alternative implementations DictionaryArray and UnionArray as part of this, currently this will significantly regress performance for them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logical_null_count implementation should obviously be consistent with logical_nulls implementation, so let's do #6740 first

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added explicit implementation of DictionaryArray::logical_null_count
i am not sure what to do about UnionArray. UnionArray::logical_nulls has non trivial logic. Can you please advise how this should be approached the best way? should I just copy that function?

cc @alamb

}

/// Returns the total number of bytes of memory pointed to by this array.
Expand Down
Loading