Repository navigation
Don't double-count the offset when slicing struct data from C++ - #7596
westonpace wants to merge 6 commits into
Conversation
alamb
left a comment
There was a problem hiding this comment.
Thank you @westonpace -- I had some questions about the test, but otherwise this seems reasonable to me
| Some(NullBuffer::from(vec![true, false, true, true, true, true])), | ||
| ); | ||
|
|
||
| let cpp_sliced_array = make_array( |
There was a problem hiding this comment.
I wonder if there is some way to add a reproducer with actual data that came from C/C++. I am not sure how to verify that this reproducer accurately reflects the C/C++ code (not that I doubt you, I just don't know how to double check it)
Maybe we can add something to https://github.com/apache/arrow-testing/tree/master/data?
Or does it only happen when passing across IPC boundaries? If so maybe we can add a test to the integration tests?
There was a problem hiding this comment.
Hmm, good question. I believe (but am not 100% sure) that the IPC format does not have an equivalent of array offsets.
However, I agree that some kind of C data integration test would be a good idea. I'll think on how best to add this. Are there any integration tests today that are able to utilize datafusion-python? If so, pyarrow makes it pretty easy to create this kind of integration testing.
There was a problem hiding this comment.
Could we use the existing integration test setup in
https://github.com/apache/arrow-rs/tree/main/arrow-integration-testing
https://github.com/apache/arrow-rs/tree/main/arrow-integration-test
| } | ||
|
|
||
| #[test] | ||
| fn test_struct_array_data_slice() { |
There was a problem hiding this comment.
I did verify that this test fails without the change in this PR
assertion failed: (offset + length) <= self.len()
thread 'array::struct_array::tests::test_struct_array_data_slice' panicked at arrow-data/src/data.rs:550:9:
assertion failed: (offset + length) <= self.len()
|
It seems like it also fixes my issue: |
|
Thanks @rluvaton -- I think the only thing we are waiting on for this PR is some additional testing |
| data_type: self.data_type().clone(), | ||
| len: length, | ||
| offset: new_offset, | ||
| offset: self.offset, |
There was a problem hiding this comment.
I would add a comment that offsets are for buffers and child data,
buffers are empty for struct (I would add an assertion for that) and offset for child data is cumulative, so keeping this offset as we already update the offset for the children.
There was a problem hiding this comment.
Seeing as the offsets propagate, wouldn't it maybe be better to just keep this as offset: new_offset and not touch child_data at all?
There was a problem hiding this comment.
That does seem simpler. It looks like impl From<ArrayData> for StructArray already pushes offsets into children so it isn't less work but it keeps the work in one spot instead of two as this entire if statement could be removed.
Sorry though, I've been away from this for so long I don't even really remember the source issue.
|
Should we create a followup issue for creating an integration test for this case, to get this PR moving along? |
Yeah -- or maybe ask a tool like codex or claude to try and make one |
|
Took the liberty of merging up from main & applying the comments as suggested by @rluvaton |
|
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
…ata (#10835) # Which issue does this PR close? - Closes #7750. - Closes #7595. # Rationale for this change Slicing a `Struct` `ArrayData` pushed the new offset into the child data *and* also added it to the parent's own `offset`. Rebuilding an array from the sliced data (`make_array` / `From<ArrayData> for StructArray`) then windowed the already-windowed children a second time and panicked with `(offset + length) <= self.len()`. This is a regression from 54.3.0 (it panics on 55.0.0 through current main). This finishes the approach from #7596, which @alamb approved pending additional testing before it went stale. # What changes are included in this PR? In the `Struct` arm of `ArrayData::slice`, keep `self.offset` unchanged and let the cumulative child offsets carry the slice (a struct's `ArrayData` has no buffers of its own, now guarded by an assert). # Are these changes tested? Yes. Added `test_struct_array_data_slice` (the C data interface offset representation) and `test_make_array_sliced_struct_data` (the exact #7750 reproducer), both failing before the change and passing after. Verified no regressions across arrow-data, arrow-array, arrow-select, arrow-ord, arrow-cast, and arrow-ipc. # Are there any user-facing changes? Slicing a struct `ArrayData` no longer panics on rebuild. The sliced `ArrayData` now represents the offset on its children with the parent offset unchanged — consistent with how `From<ArrayData> for StructArray` already interprets it.
…ata (apache#10835) # Which issue does this PR close? - Closes apache#7750. - Closes apache#7595. # Rationale for this change Slicing a `Struct` `ArrayData` pushed the new offset into the child data *and* also added it to the parent's own `offset`. Rebuilding an array from the sliced data (`make_array` / `From<ArrayData> for StructArray`) then windowed the already-windowed children a second time and panicked with `(offset + length) <= self.len()`. This is a regression from 54.3.0 (it panics on 55.0.0 through current main). This finishes the approach from apache#7596, which @alamb approved pending additional testing before it went stale. # What changes are included in this PR? In the `Struct` arm of `ArrayData::slice`, keep `self.offset` unchanged and let the cumulative child offsets carry the slice (a struct's `ArrayData` has no buffers of its own, now guarded by an assert). # Are these changes tested? Yes. Added `test_struct_array_data_slice` (the C data interface offset representation) and `test_make_array_sliced_struct_data` (the exact apache#7750 reproducer), both failing before the change and passing after. Verified no regressions across arrow-data, arrow-array, arrow-select, arrow-ord, arrow-cast, and arrow-ipc. # Are there any user-facing changes? Slicing a struct `ArrayData` no longer panics on rebuild. The sliced `ArrayData` now represents the offset on its children with the parent offset unchanged — consistent with how `From<ArrayData> for StructArray` already interprets it.
…ata (apache#10835) # Which issue does this PR close? - Closes apache#7750. - Closes apache#7595. # Rationale for this change Slicing a `Struct` `ArrayData` pushed the new offset into the child data *and* also added it to the parent's own `offset`. Rebuilding an array from the sliced data (`make_array` / `From<ArrayData> for StructArray`) then windowed the already-windowed children a second time and panicked with `(offset + length) <= self.len()`. This is a regression from 54.3.0 (it panics on 55.0.0 through current main). This finishes the approach from apache#7596, which @alamb approved pending additional testing before it went stale. # What changes are included in this PR? In the `Struct` arm of `ArrayData::slice`, keep `self.offset` unchanged and let the cumulative child offsets carry the slice (a struct's `ArrayData` has no buffers of its own, now guarded by an assert). # Are these changes tested? Yes. Added `test_struct_array_data_slice` (the C data interface offset representation) and `test_make_array_sliced_struct_data` (the exact apache#7750 reproducer), both failing before the change and passing after. Verified no regressions across arrow-data, arrow-array, arrow-select, arrow-ord, arrow-cast, and arrow-ipc. # Are there any user-facing changes? Slicing a struct `ArrayData` no longer panics on rebuild. The sliced `ArrayData` now represents the offset on its children with the parent offset unchanged — consistent with how `From<ArrayData> for StructArray` already interprets it.
…ata (apache#10835) # Which issue does this PR close? - Closes apache#7750. - Closes apache#7595. # Rationale for this change Slicing a `Struct` `ArrayData` pushed the new offset into the child data *and* also added it to the parent's own `offset`. Rebuilding an array from the sliced data (`make_array` / `From<ArrayData> for StructArray`) then windowed the already-windowed children a second time and panicked with `(offset + length) <= self.len()`. This is a regression from 54.3.0 (it panics on 55.0.0 through current main). This finishes the approach from apache#7596, which @alamb approved pending additional testing before it went stale. # What changes are included in this PR? In the `Struct` arm of `ArrayData::slice`, keep `self.offset` unchanged and let the cumulative child offsets carry the slice (a struct's `ArrayData` has no buffers of its own, now guarded by an assert). # Are these changes tested? Yes. Added `test_struct_array_data_slice` (the C data interface offset representation) and `test_make_array_sliced_struct_data` (the exact apache#7750 reproducer), both failing before the change and passing after. Verified no regressions across arrow-data, arrow-array, arrow-select, arrow-ord, arrow-cast, and arrow-ipc. # Are there any user-facing changes? Slicing a struct `ArrayData` no longer panics on rebuild. The sliced `ArrayData` now represents the offset on its children with the parent offset unchanged — consistent with how `From<ArrayData> for StructArray` already interprets it.
Which issue does this PR close?
Rationale for this change
See PR
What changes are included in this PR?
ArrayData.slice was changed so that the new offset is only pushed into the child arrays during slicing. It is not added to the parent data's offset.
Are there any user-facing changes?
No