Rich-T-kid commented on code in PR #11145:
URL: https://github.com/apache/arrow-rs/pull/11145#discussion_r4074522361


##########
arrow-array/src/array/map_array.rs:
##########
@@ -32,6 +32,26 @@ use std::sync::Arc;
 /// [`MapArray`] is physically a [`ListArray`] of key values pairs stored as 
an `entries`
 /// [`StructArray`] with 2 child fields.
 ///
+/// # Slicing
+///
+/// Slicing a `MapArray` via [`Self::slice`] creates a new `MapArray` without
+/// copying any data. The sliced array shares the same `entries` child array 
and
+/// only narrows its offsets and validity, which means:
+///
+/// 1. [`Self::entries`], [`Self::keys`] and [`Self::values`] are unchanged and
+///    may contain entries both before and after the slice.
+/// 2. [`Self::offsets`] do not necessarily start at `0`, nor cover all 
entries.
+///
+/// For example, given a `MapArray` holding the three maps `{a: 1, b: 2}`,
+/// `{c: 3}` and `{d: 4, e: 5}`, the `entries` array holds five key-value pairs
+/// and the offsets are `[0, 2, 3, 5]`. Calling `slice(1, 1)` yields a 
`MapArray`
+/// holding the single map `{c: 3}`, but [`Self::keys`] still returns all five
+/// keys `a, b, c, d, e` and [`Self::offsets`] is `[2, 3]`. Use the offsets, or
+/// [`Self::value`], to find the entries belonging to each map.
+///
+/// The same applies to any `MapArray` constructed with offsets that do not 
start
+/// at `0` or do not extend to the end of `entries`.

Review Comment:
   nice I like that you provided an example



##########
arrow-array/src/array/map_array.rs:
##########
@@ -210,22 +230,40 @@ impl MapArray {
     ///
     /// Unlike [`Self::value_offsets`] this returns the [`OffsetBuffer`]
     /// allowing for zero-copy cloning
+    ///
+    /// Note: The offsets may not start at `0` and may not cover all entries in
+    /// [`Self::entries`]. This can happen when the map array was sliced via
+    /// [`Self::slice`]. See documentation for [`Self`] for more details.

Review Comment:
   👍 



-- 
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]

Reply via email to