alamb commented on code in PR #11710:
URL: https://github.com/apache/arrow-rs/pull/11710#discussion_r4317650009
##########
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
+/// ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┐
+/// ┌─────────────────┐ ┌─────────┐ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ┐
+/// │ │ A │ │ 2 │ │ A logical
index 0: before offset, not visible
+/// ├─────────────────┤ ├─────────┤ ┌─────────────────┐ ◄── offset = 1
+/// │ │ D │ │ 3 │ │ │ A │ logical
index 1 < run_ends[0] = 2, so 'A'
+/// ├─────────────────┤ ├─────────┤ ├─────────────────┤
+/// │ │ B │ │ 6 │ │ │ D │ logical
index 2 < run_ends[1] = 3, so 'D'
+/// └─────────────────┘ └─────────┘ ├─────────────────┤
+/// │ values run_ends │ │ B │ logical
index 3 < run_ends[2] = 6, so 'B'
+/// └─────────────────┘ ◄── offset +
len = 4
+/// └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┘ B logical
index 4: after offset + len, not visible
+/// ├ ─ ─ ─ ─ ─ ─ ─ ─ ┤
+/// RunArray B logical
index 5: after offset + len, not visible
+/// offset = 1, len = 3 └ ─ ─ ─ ─ ─ ─ ─ ─ ┘
+///
+/// Logical array
+/// Contents
+/// ```
+///
+/// # Slicing of the child arrays
+///
+/// Note that the `values` array may itself have a non-zero offset. Run `i`
+/// always corresponds to `values.value(i)`, the logical indexing
+/// of the `values` array, including any offset.
+///
+/// The `run_ends` are never sliced.
Review Comment:
I did this in 487de5fbc0
##########
arrow-array/src/array/run_array.rs:
##########
@@ -405,6 +462,19 @@ impl<R: RunEndIndexType> RunArray<R> {
}
}
+/// Converts an [`ArrayData`] into a [`RunArray`].
+///
+/// The `len` and `offset` of `data` become the logical length and offset of
the
+/// [`RunArray`]; see the [`RunArray`] documentation for how they relate to the
+/// run ends.
+///
+/// The `offset` and `len` of the `run_ends` child are **ignored**: the entire
+/// buffer of the `run_ends` child is used as the physical run ends.
Review Comment:
Updated in 487de5fbc0
--
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]