You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Slicing a struct ArrayData with an offset double-counts the offset #7595
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.
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.
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.
Activity
westonpace commentedon Jun 3, 2025
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.westonpace commentedon Jun 3, 2025
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_arrayphase, 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.
docs(arrow-data): Document how `ArrayData::offset` applies to buffers…
fix(arrow-data): don't double-count offset when slicing struct ArrayD…
docs(arrow-data): Document how `ArrayData::offset` applies to buffers…
docs(arrow-data): Document how `ArrayData::offset` applies to buffers…
fix(arrow-data): don't double-count offset when slicing struct ArrayD…
docs(arrow-data): Document how `ArrayData::offset` applies to buffers…
fix(arrow-data): don't double-count offset when slicing struct ArrayD…
docs(arrow-data): Document how `ArrayData::offset` applies to buffers…
fix(arrow-data): don't double-count offset when slicing struct ArrayD…