Skip to content

doc: Describe potential footgun in MapArray::keys and values - #11145

Merged
Jefffrey merged 2 commits into
apache:mainfrom
neilconway:neilc/doc-maparray-keys
Sep 23, 2026
Merged

Jefffrey merged 2 commits into
apache:mainfrom
neilconway:neilc/doc-maparray-keys

Conversation

@neilconway

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • N/A

Rationale for this change

The behavior of the keys and values methods of a MapArray can be a bit surprising. This PR documents that behavior; consistent with the documentation for ListArray::values, which behaves similarly.

What changes are included in this PR?

  • Doc additions only

Are these changes tested?

Existing tests pass.

Are there any user-facing changes?

No.

@neilconway

Copy link
Copy Markdown
Contributor Author

Noticed this in apache/datafusion#25543

@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-array labels Sep 20, 2026

@Rich-T-kid Rich-T-kid 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.

makes sense to me. I left a suggestion but its fine as it is.

In my opinion, the extra info on how to get the specific slice range your looking for would be better placed as a doc comment on [Self::value_offsets].

Comment thread arrow-array/src/array/map_array.rs Outdated
@neilconway

Copy link
Copy Markdown
Contributor Author

@Rich-T-kid Thanks for the suggestions! I made some improvements and additions based on your feedback.

@Rich-T-kid Rich-T-kid 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.

I think this is very neat, thanks @neilconway

Comment on lines +45 to +53
/// 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`.

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.

nice I like that you provided an example

Comment on lines +234 to +236
/// 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.

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.

👍

@Jefffrey Jefffrey added the documentation Improvements or additions to documentation label Sep 23, 2026
@Jefffrey
Jefffrey merged commit 002cc1c into apache:main Sep 23, 2026
41 checks passed
@Jefffrey

Copy link
Copy Markdown
Contributor

thanks @neilconway & @Rich-T-kid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-array documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants