mbutrovich commented on code in PR #11710:
URL: https://github.com/apache/arrow-rs/pull/11710#discussion_r4339284213
##########
arrow-array/src/array/run_array.rs:
##########
@@ -73,12 +73,62 @@ 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` 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`.
Review Comment:
> if `len > 0`, the last run end is greater than or equal to `offset + len`.
Is the `len > 0` condition intended? The [REE
layout](https://github.com/apache/arrow/blob/373d64c02cb23663b63c5853099fca43a46c39fc/docs/source/format/Columnar.rst?plain=1#L1089-L1160)
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](https://github.com/apache/arrow/blob/373d64c02cb23663b63c5853099fca43a46c39fc/cpp/src/arrow/util/ree_util.cc#L247-L254),
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.
--
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]