Skip to content

fix(arrow-cast): only cast visible elements for lists and maps - #11359

Merged
Jefffrey merged 1 commit into
apache:mainfrom
neilconway:neilc/fix-sliced-list-cast
Oct 4, 2026
Merged

Jefffrey merged 1 commit into
apache:mainfrom
neilconway:neilc/fix-sliced-list-cast

Conversation

@neilconway

@neilconway neilconway commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • N/A

Rationale for this change

Casting a List, LargeList, ListView or Map cast its whole child array. When the input to the cast was sliced, this was both inefficient and could also result in spurious errors, if a value outside the visible span made the cast fail (with safe: false).

For lists and maps, we now cast only the range of child values that the rows span, and rebase the offsets. For ListView, a row can point anywhere in the values buffer, so the visible elements might not form a contiguous span. Casting only the visible values would be expensive and require copies, so we instead settle for an overestimate: we use the lowest starting offset and highest ending offset of any row. This is an improvement over the previous behavior, but it does result in unnecessarily casting values that are inside that range but not part of any row.

What changes are included in this PR?

  • Only look at the elements in the visible span, for each of the casts in question
  • The value buffer of the cast result is potentially smaller than the input value buffer, in which case we need to revise the offset buffer
  • Add unit tests

Are these changes tested?

Yes; existing tests pass, new tests added.

Are there any significant user-facing changes?

No.

AI usage

Developed and revised with Claude Code (Opus 5.5). I have reviewed and understand the resulting code.

…r to

Casting a List, LargeList, ListView or Map cast its whole child array,
including values outside a slice. A value outside the slice that could
not be cast made the cast fail with `safe: false`. With `safe: true` it
became null, which still failed when the target child field was
non-nullable, as map keys always are. The result also kept the whole
cast child array.

Cast only the range of child values that the rows span, and rebase the
offsets. For ListView, rows can be in any order, so that range can still
include values that no row in the slice uses.
@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-cast labels Oct 3, 2026
@neilconway neilconway changed the title fix(arrow-cast): only cast the visible span for lists and maps fix(arrow-cast): only cast visible elements for lists and maps Oct 3, 2026
@Jefffrey Jefffrey added the bug label Oct 4, 2026
@Jefffrey
Jefffrey added this pull request to the merge queue Oct 4, 2026
@Jefffrey

Jefffrey commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

thanks @neilconway

Merged via the queue into apache:main with commit 615f0bc Oct 4, 2026
35 checks passed
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-cast bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants