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

feat(arrow-array): add from_iter for DictionaryArray for building BinaryDictionaryArray #6922

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rluvaton
Copy link
Contributor

@rluvaton rluvaton commented Dec 31, 2024

Which issue does this PR close?

make it easier to write tests for #6923

Rationale for this change

You can't build BinaryDictionaryArray from iterator of bytes

What changes are included in this PR?

added from_iter from iterator of &[u8] and from iterator of Option<&[u8]>

Are there any user-facing changes?

Yes.

There are breaking changes, see the failing example below with the fix:

#[test]
fn test_dictionary_all_string_nulls() {
-   let test = vec![None, None, None];
+   let test = vec![None::<&str>, None::<&str>, None::<&str>];
    let array: DictionaryArray<Int32Type> = test.into_iter().collect();
    array
        .into_data()
        .validate_full()
        .expect("All null array has valid array data");
}

I'll fix the broken tests when I know this change is desired

@github-actions github-actions bot added the arrow Changes to the arrow crate label Dec 31, 2024
@alamb alamb added the api-change Changes to the arrow API label Jan 1, 2025
Comment on lines +741 to +745
it.for_each(|i| {
builder
.append(i)
.expect("Unable to append a value to a dictionary array.");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The Extend<Option<V>> uses append_option. Hence the two FromIterator impls here. 👍🏼

Comment on lines +712 to +716
impl<'a, T: ArrowDictionaryKeyType> FromIterator<Option<&'a [u8]>> for DictionaryArray<T> {
fn from_iter<I: IntoIterator<Item = Option<&'a [u8]>>>(iter: I) -> Self {
let it = iter.into_iter();
let (lower, _) = it.size_hint();
let mut builder = BinaryDictionaryBuilder::with_capacity(lower, 256, 1024);
Copy link
Contributor

Choose a reason for hiding this comment

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

There is another FromIterator<Option<&'a str>> for DictionaryArray<T> for strings, which at first glance looks possible to combine. (Both use the GenericByteDictionaryBuilder with either strings, or bytes). Have you tried that, and do you think it's worthwhile?

@wiedld
Copy link
Contributor

wiedld commented Jan 3, 2025

Tests are not yet fixed since @rluvaton wanted to confirm it was worthwhile. @alamb -- see comments above, hopefully it speeds up your review.

@alamb
Copy link
Contributor

alamb commented Jan 4, 2025

TLDR is that the idea is a good one -- thank you @rluvaton and @wiedld for the review

In general, I think the most important thing is to make sure this isn't a breaking change, otherwise we can't merge it until Feb due to the current release schedule: https://github.com/apache/arrow-rs?tab=readme-ov-file#release-versioning-and-schedule

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-change Changes to the arrow API arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants