Repository navigation
perf: speed up DictionaryArray hashing #26159
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
a76b7dd
d5b570e
2e011c9
732211b
88d50e0
9e86750
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 |
|---|---|---|
|
|
@@ -543,23 +543,27 @@ fn hash_dictionary_scatter< | |
| if let Some(key) = key { | ||
| let idx = key.as_usize(); | ||
| if !HAS_NULL_VALUES || dict_values.is_valid(idx) { | ||
| if MULTI_COL { | ||
| *hash = combine_hashes(dict_hashes[idx], *hash); | ||
| // SAFETY: `idx` is a valid Arrow dict key, in-bounds for `dict_hashes`. | ||
| let dict_hash = unsafe { *dict_hashes.get_unchecked(idx) }; | ||
|
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. should add a saftey comment
Contributor
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. the safety is predicated o the fact that the key came from a valid Arrow array and thus is guaranteed to be in bound of the dictionary
Contributor
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. (should also post unsafe comment below too) |
||
| *hash = if MULTI_COL { | ||
| combine_hashes(dict_hash, *hash) | ||
| } else { | ||
| *hash = dict_hashes[idx]; | ||
| } | ||
| dict_hash | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| for (hash, key) in hashes_buffer.iter_mut().zip(array.keys().values()) { | ||
| let idx = key.as_usize(); | ||
| if !HAS_NULL_VALUES || dict_values.is_valid(idx) { | ||
| if MULTI_COL { | ||
| *hash = combine_hashes(dict_hashes[idx], *hash); | ||
| // SAFETY: `idx` is a valid Arrow dict key, in-bounds for `dict_hashes`. | ||
| let dict_hash = unsafe { *dict_hashes.get_unchecked(idx) }; | ||
| *hash = if MULTI_COL { | ||
| combine_hashes(dict_hash, *hash) | ||
| } else { | ||
| *hash = dict_hashes[idx]; | ||
| } | ||
| dict_hash | ||
| }; | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1304,6 +1308,9 @@ mod tests { | |
| use std::hash::{BuildHasherDefault, Hasher}; | ||
| use std::sync::Arc; | ||
|
|
||
| #[cfg(not(feature = "force_hash_collisions"))] | ||
| use arrow::buffer::{NullBuffer, ScalarBuffer}; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[cfg(not(feature = "force_hash_collisions"))] | ||
|
|
@@ -1856,8 +1863,6 @@ mod tests { | |
| // Tests actual values of hashes, which are different if forcing collisions | ||
| #[cfg(not(feature = "force_hash_collisions"))] | ||
| fn create_hashes_for_list_view_arrays() { | ||
| use arrow::buffer::{NullBuffer, ScalarBuffer}; | ||
|
|
||
|
Comment on lines
-1859
to
-1860
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. quality of life changes here |
||
| // Create values array: [0, 1, 2, 3, null, 5] | ||
| let values = Arc::new(Int32Array::from(vec![ | ||
| Some(0), | ||
|
|
@@ -1906,8 +1911,6 @@ mod tests { | |
| // Tests actual values of hashes, which are different if forcing collisions | ||
| #[cfg(not(feature = "force_hash_collisions"))] | ||
| fn create_hashes_for_large_list_view_arrays() { | ||
| use arrow::buffer::{NullBuffer, ScalarBuffer}; | ||
|
|
||
| // Create values array: [0, 1, 2, 3, null, 5] | ||
| let values = Arc::new(Int32Array::from(vec![ | ||
| Some(0), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.