doc: Describe potential footgun in MapArray::keys and values - #11145
Merged
Merged
Conversation
Contributor
Author
|
Noticed this in apache/datafusion#25543 |
Rich-T-kid
approved these changes
Sep 20, 2026
Contributor
Author
|
@Rich-T-kid Thanks for the suggestions! I made some improvements and additions based on your feedback. |
Rich-T-kid
approved these changes
Sep 22, 2026
Rich-T-kid
left a comment
Contributor
There was a problem hiding this comment.
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`. |
Contributor
There was a problem hiding this comment.
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. |
Jefffrey
approved these changes
Sep 23, 2026
Contributor
|
thanks @neilconway & @Rich-T-kid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
The behavior of the
keysandvaluesmethods of aMapArraycan be a bit surprising. This PR documents that behavior; consistent with the documentation forListArray::values, which behaves similarly.What changes are included in this PR?
Are these changes tested?
Existing tests pass.
Are there any user-facing changes?
No.