Skip to content

docs(arrow-data): Document how ArrayData::offset applies to buffers, child_data and nulls - #10838

Merged
alamb merged 1 commit into
apache:mainfrom
alamb:alamb/document_array_data_offset
Aug 26, 2026
Merged

docs(arrow-data): Document how ArrayData::offset applies to buffers, child_data and nulls#10838
alamb merged 1 commit into
apache:mainfrom
alamb:alamb/document_array_data_offset

Conversation

@alamb

@alamb alamb commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

The invariants governing ArrayData::offset are currently documented only on the private fields of ArrayData, so they never appear in rendered rustdoc.

  • offset field
    /// The offset in number of items (not bytes).
    ///
    /// The offset applies to [`Self::child_data`] and [`Self::buffers`]. It
    /// does NOT apply to [`Self::nulls`].
    offset: usize,
  • child_data field
    /// The child(ren) of this array.
    ///
    /// Only non-empty for nested types, such as `ListArray` and
    /// `StructArray`.
    ///
    /// The first logical element in each child element begins at `offset`.
    ///
    /// If the child element also has an offset then these offsets are
    /// cumulative.
    child_data: Vec<ArrayData>,

This was making it hard for me to reason about what a correct fix looks like when offset-handling like #7595 / #7750 and #10835, where the correct output of ArrayData::slice depends on these definitions

What changes are included in this PR?

This PR surfaces those invariants on the public accessors so they are visible in the docs and can be cited as the authority in code and reviews.

Are these changes tested?

Docs only; covered by CI doc builds.

Are there any user-facing changes?

Documentation only — no behavior changes.

@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-data labels Aug 25, 2026
@alamb
alamb force-pushed the alamb/document_array_data_offset branch from 562a08f to 80f24bb Compare August 25, 2026 20:57
@alamb
alamb force-pushed the alamb/document_array_data_offset branch from 80f24bb to ffbc3d5 Compare August 25, 2026 21:06
Comment thread arrow-data/src/data.rs
/// For non-nested types, the offset skips leading elements in the buffers.
/// Logical element `i` is stored at physical position `offset + i`.
///
/// For example, with `offset = 2` and `len = 3` the following array

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent quite a while trying to make comments and ASCII art that illustrate what is going on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

Comment thread arrow-data/src/data.rs
/// logical index 0 1 2
/// ```
///
/// # Offsets for Struct types

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the offset rules are different for other types (like Unions) but this PR is already pretty tricky so we can perhaps add more detailed information as a follow on PR

Comment thread arrow-data/src/data.rs
/// For non-nested types, the offset skips leading elements in the buffers.
/// Logical element `i` is stored at physical position `offset + i`.
///
/// For example, with `offset = 2` and `len = 3` the following array

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@alamb
alamb merged commit aa9b923 into apache:main Aug 26, 2026
34 checks passed
@alamb

alamb commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

I am happy to change this documentation if we find other issues with it. However, I am merging it in for now to unblock progress on #10835

@Jefffrey Jefffrey added the documentation Improvements or additions to documentation label Aug 27, 2026
jaideeppyne added a commit to jaideeppyne/arrow-rs that referenced this pull request Aug 27, 2026
The previous revision left `self.offset` on the parent and windowed the
children, which still applied the slice twice whenever the input already
carried a non-zero offset (as an FFI/C-data-interface import does):
`From<ArrayData> for StructArray` re-windows every child by the parent
offset, so `slice()` on such data panicked with the same
`(offset + length) <= self.len()` assertion.

Per the invariants documented in apache#10838, a struct's offset composes with
each child's offset, so the window has to be recorded in exactly one
place. Push the whole cumulative offset (`self.offset + offset`) into the
children and reset the parent's offset to 0.

Keeping the window on the children (rather than only on the parent) also
preserves what the IPC writer assumes: it serialises struct `child_data`
without applying the parent's offset, so a parent-offset-only slice would
have written the wrong values and defeated buffer truncation.

Add a regression test for slicing struct data that already carries an
offset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-data documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants