Skip to content

docs: document RunArray logical offset/len and child array slicing - #11710

Merged
alamb merged 13 commits into
apache:mainfrom
alamb:alamb/document_run_array_offsets
Oct 30, 2026
Merged

alamb merged 13 commits into
apache:mainfrom
alamb:alamb/document_run_array_offsets

Conversation

@alamb

@alamb alamb commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

While reviewing #11668 I was unclear about the relationship between a RunArray's logical offset / len and the contents of its run_ends child as it was not documented anywhere on RunArray itself

What changes are included in this PR?

Documentation only, on pub struct RunArray:

Are these changes tested?

Yes, by CI

Are there any significant user-facing changes?

Only docs

@github-actions github-actions Bot added the arrow-core Core crates related to representing arrow data label Oct 19, 2026
@alamb alamb added the documentation Improvements or additions to documentation label Oct 19, 2026
@alamb
alamb marked this pull request as ready for review October 19, 2026 15:11
/// ├─────────────────┤
/// RunArray │ B │ run length of 'B' = run_ends[2] - run_ends[1] = 3
/// length = 3 └─────────────────┘
/// offset = 0, len = 6 └─────────────────┘

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.

this was a bug

///
/// ```text
/// ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┐
/// ┌─────────────────┐ ┌─────────┐ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ┐

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 really wanted this PR when reviewing #11668 (review)

Comment thread arrow-array/src/array/run_array.rs Resolved
Comment thread arrow-array/src/array/run_array.rs Resolved
///
/// The values in `run_ends` represent indexes of the *unsliced* logical array.
/// This allows zero-copy [`RunArray::slice`]: `run_ends` and `values` are left
/// untouched and only `offset` and `len` are adjusted.

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.

side note, actually had an idea where we did actually slice them:

though havent had time to explore this further

@mbutrovich mbutrovich left a comment

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.

Thanks for writing this up @alamb! Since the bug originated from my attempts with PBT, I'm happy to see more invariants spelled out.

/// * every run end is greater than zero and `run_ends` is strictly increasing
/// * `run_ends` has no null values
/// * `run_ends` and `values` have the same length
/// * if `len > 0`, the last run end is greater than or equal to `offset + len`.

@mbutrovich mbutrovich Oct 21, 2026 •

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.

if len > 0, the last run end is greater than or equal to offset + len.

Is the len > 0 condition intended? The REE layout does not mention a parent offset, so as I read it the spec is silent. C++ requires the last run end to cover offset + length when the run ends are non-empty, even for length == 0. With run ends [1], offset = 2 and len = 0, validate_full accepts the array on main and, as I read the C++ code, C++ rejects it.

Comment thread arrow-buffer/src/buffer/run.rs Outdated
/// Panics if the [`RunArray` invariants] are not satisfied:
///
/// - `run_ends` does not contain strictly increasing values greater than zero
/// - The last value of `run_ends` is less than `logical_offset + logical_length`

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.

  • The last value of run_ends is less than logical_offset + logical_length

Should this item say "when logical_length is not 0"? The code only asserts it under if logical_length != 0, and the new # offset and len section on RunArray already says len > 0.

@Rich-T-kid

Copy link
Copy Markdown
Contributor

merging up to fix CI

@alamb

alamb commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Thank you -- sorry for the delay, I have addressed @mbutrovich 's comments now

@alamb
alamb enabled auto-merge October 30, 2026 20:19
@alamb
alamb added this pull request to the merge queue Oct 30, 2026
Merged via the queue into apache:main with commit dd6454d Oct 30, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-core Core crates related to representing arrow data documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants