Skip to content

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

Closed

Description

@davidhewitt

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.

Activity

  1. added
    bug
    on May 5, 2025
  2. davidhewitt commented on May 5, 2025

    @davidhewitt
    ContributorAuthor

    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.

  3. davidhewitt commented on May 5, 2025

    @davidhewitt
    ContributorAuthor

    I suspect concat also has a similar problem.

  4. added
    enhancement
    and removed
    bug
    on May 5, 2025
  5. davidhewitt commented on Aug 11, 2025

    @davidhewitt
    ContributorAuthor

    Fixed by #7519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions