-
Notifications
You must be signed in to change notification settings - Fork 839
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
Fix merge_dictionary_values in selection kernels #4833
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,7 +152,7 @@ pub fn merge_dictionary_values<K: ArrowDictionaryKeyType>( | |
) -> Result<MergedDictionaries<K>, ArrowError> { | ||
let mut num_values = 0; | ||
|
||
let mut values = Vec::with_capacity(dictionaries.len()); | ||
let mut values_arrays = Vec::with_capacity(dictionaries.len()); | ||
let mut value_slices = Vec::with_capacity(dictionaries.len()); | ||
|
||
for (idx, dictionary) in dictionaries.iter().enumerate() { | ||
|
@@ -164,11 +164,13 @@ pub fn merge_dictionary_values<K: ArrowDictionaryKeyType>( | |
(None, None) => None, | ||
}; | ||
let keys = dictionary.keys().values(); | ||
let values_mask = compute_values_mask(keys, key_mask.as_ref()); | ||
let v = dictionary.values().as_ref(); | ||
num_values += v.len(); | ||
value_slices.push(get_masked_values(v, &values_mask)); | ||
values.push(v) | ||
let values = dictionary.values().as_ref(); | ||
let values_mask = compute_values_mask(keys, key_mask.as_ref(), values.len()); | ||
|
||
let masked_values = get_masked_values(values, &values_mask); | ||
num_values += masked_values.len(); | ||
value_slices.push(masked_values); | ||
values_arrays.push(values) | ||
} | ||
|
||
// Map from value to new index | ||
|
@@ -202,7 +204,7 @@ pub fn merge_dictionary_values<K: ArrowDictionaryKeyType>( | |
|
||
Ok(MergedDictionaries { | ||
key_mappings, | ||
values: interleave(&values, &indices)?, | ||
values: interleave(&values_arrays, &indices)?, | ||
}) | ||
} | ||
|
||
|
@@ -211,9 +213,10 @@ pub fn merge_dictionary_values<K: ArrowDictionaryKeyType>( | |
fn compute_values_mask<K: ArrowNativeType>( | ||
keys: &ScalarBuffer<K>, | ||
mask: Option<&BooleanBuffer>, | ||
max_key: usize, | ||
) -> BooleanBuffer { | ||
let mut builder = BooleanBufferBuilder::new(keys.len()); | ||
builder.advance(keys.len()); | ||
let mut builder = BooleanBufferBuilder::new(max_key); | ||
builder.advance(max_key); | ||
|
||
match mask { | ||
Some(n) => n | ||
|
@@ -330,4 +333,15 @@ mod tests { | |
assert_eq!(&merged.key_mappings[0], &[0, 0, 0, 1, 0]); | ||
assert_eq!(&merged.key_mappings[1], &[]); | ||
} | ||
|
||
#[test] | ||
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 verified that without the changes in this PR this test fails like this:
|
||
fn test_merge_keys_smaller() { | ||
let values = StringArray::from_iter_values(["a", "b"]); | ||
let keys = Int32Array::from_iter_values([1]); | ||
let a = DictionaryArray::new(keys, Arc::new(values)); | ||
|
||
let merged = merge_dictionary_values(&[&a], None).unwrap(); | ||
let expected = StringArray::from(vec!["b"]); | ||
assert_eq!(merged.values.as_ref(), &expected); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is the bug, the length of the values_mask should match that of the values array not the keys. In all of the existing tests the number of keys outnumbered the number of values, not helped by the heuristic to trigger merging being based off the total number of keys outnumbering the total number of values.