Skip to content

Slicing a struct ArrayData with an offset double-counts the offset #7595

Closed

Description

@westonpace

Describe the bug

When an ArrayData representing a struct array is sliced then the new offset is incorrectly doubled since it is both set to the struct array and it is pushed down into child arrays.

To Reproduce

        let x = Int32Array::from(vec![0, 1, 2, 3, 4, 5]);
        let struct_array = StructArray::new(
            Fields::from(vec![Field::new("x", DataType::Int32, true)]),
            vec![Arc::new(x.clone())],
            None,
        )
        .into_data();
        let sliced = struct_array.slice(1, 4);
        // Panics
        let arr = make_array(sliced);

Expected behavior

There are two options. Either add the offset to the parent data's offset or push the offset into the children. Since the StructArray version of slicing does the latter (StructArray has no self-offset) I would recommend that approach.

Additional context

This problem arose for us because we accept data from pyarrow. In pyarrow struct slicing is done by setting the offset of the parent and not pushing it down into the children (the opposite of the approach taken by arrow-rs). This caused a panic when we attempted to cross the C data boundary.

Activity

  1. added
    bug
    on Jun 3, 2025
  2. westonpace commented on Jun 3, 2025

    @westonpace
    MemberAuthor

    Note: this may be sort of a regression as #7366 changed the way we handle the struct offset in make_array. Although I think what happened is that the previous behavior was silent corruption and the new behavior is now a panic.

  3. westonpace commented on Jun 3, 2025

    @westonpace
    MemberAuthor

    Actually, I think this could be a true regression for rust-only workflows that sliced struct array data. Previously, it would have introduced offsets in parent datas, but those offsets would have been ignored during the later make_array phase, and the end result would be correct.

    Now, due to #7366 , we will not ignore offsets in parent datas, and so that workflow which worked previously will now either panic or return incorrect values.

  4. added a commit that references this issue on Sep 1, 2026
    c44f8d4
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions