alamb commented on code in PR #11710:
URL: https://github.com/apache/arrow-rs/pull/11710#discussion_r4315537186
##########
arrow-array/src/array/run_array.rs:
##########
@@ -73,12 +73,59 @@ macro_rules! ree_map {
/// └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┘ │ B │
/// ├─────────────────┤
/// RunArray │ B │ run length
of 'B' = run_ends[2] - run_ends[1] = 3
-/// length = 3 └─────────────────┘
+/// offset = 0, len = 6 └─────────────────┘
Review Comment:
this was a bug
##########
arrow-array/src/array/run_array.rs:
##########
@@ -73,12 +73,59 @@ macro_rules! ree_map {
/// └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┘ │ B │
/// ├─────────────────┤
/// RunArray │ B │ run length
of 'B' = run_ends[2] - run_ends[1] = 3
-/// length = 3 └─────────────────┘
+/// offset = 0, len = 6 └─────────────────┘
///
/// Logical array
/// Contents
/// ```
///
+/// # `offset` and `len`
+///
+/// The [`Array::len`] and [`Array::offset`] for a `RunArray` refer to the
+/// **logical** length, not the `run_ends` and `values` child arrays. In the
+/// example above the `RunArray` has length `6` even though `run_ends` and
+/// `values` each contain `3` elements.
+///
+/// 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.
+///
+/// A [`RunArray`] must satisfy the following invariants:
+///
+/// * every run end is greater than zero and `run_ends` is strictly increasing
+/// * `run_ends` and `values` have the same length
+/// * if `len > 0`, the last run end is greater than or equal to `offset +
len`.
+///
+/// The example below shows the same array as above after calling `slice(1, 3)`
+///
+/// ```text
+/// ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┐
+/// ┌─────────────────┐ ┌─────────┐ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ┐
Review Comment:
I really wanted this PR when reviewing
https://github.com/apache/arrow-rs/pull/11668#pullrequestreview-5573669641
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]