Skip to content

interleave panics with dictionary key overflows if combined values arrays are longer than key size #7466

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

Open
davidhewitt opened this issue May 5, 2025 · 2 comments · May be fixed by #7468
Labels
enhancement Any new improvement worthy of a entry in the changelog

Comments

@davidhewitt
Copy link

davidhewitt commented May 5, 2025

Describe the bug

interleave on dictionary arrays panics if the combined length of the input value arrays is larger than the max value allowed by the dictionary key type.

To Reproduce

Sample test:

#[test]
fn test_interleave_dictionary_overflows() {
    // each array has length equal to the full dictionary key space
    let len: usize = usize::try_from(i8::MAX).unwrap();

    let a = DictionaryArray::<Int8Type>::new(
        Int8Array::from_value(0, len),
        Arc::new(Int8Array::from_value(0, len)),
    );
    let b = DictionaryArray::<Int8Type>::new(
        Int8Array::from_value(0, len),
        Arc::new(Int8Array::from_value(1, len)),
    );

    // Case 1: with a single input array, should _never_ overflow
    let values = interleave(&[&a], &[(0, 2), (0, 2)]).unwrap();
    let v = values.as_dictionary::<Int8Type>();
    let vc = v.downcast_dict::<Int8Array>().unwrap();
    let collected: Vec<_> = vc.into_iter().map(Option::unwrap).collect();
    assert_eq!(&collected, &[0, 0]);

    // Case 2: two arrays
    // Should still not overflow, there are only two values
    let values = interleave(&[&a, &b], &[(0, 2), (0, 2), (1, 1)]).unwrap();
    let v = values.as_dictionary::<Int8Type>();
    let vc = v.downcast_dict::<Int8Array>().unwrap();
    let collected: Vec<_> = vc.into_iter().map(Option::unwrap).collect();
    assert_eq!(&collected, &[0, 0, 1]);
}

Expected behavior

Tests should pass.

Additional context

It looks like there's solutions to avoid this on string dictionaries, but not other dictionary types.

@davidhewitt davidhewitt added the bug label May 5, 2025
@davidhewitt
Copy link
Author

It seems like the function merge_dictionary_values in arrow-select/src/dictionary.rs would need to be updated to support other array types. Probably just primitive arrays is good enough?

It might be simplest to just use PrimitiveDictionaryBuilder rather than make the Interner generic on the value type.

@davidhewitt
Copy link
Author

I suspect concat also has a similar problem.

@tustvold tustvold added enhancement Any new improvement worthy of a entry in the changelog and removed bug labels May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants