Skip to content

Conversation

@Jefffrey
Copy link
Contributor

@Jefffrey Jefffrey commented Jan 27, 2026

Which issue does this PR close?

Rationale for this change

While we do have support for casting list views, some cases are missing. This PR goes through the list casting logic for all list types and tries to ensure we have comprehensive & consistent coverage for casting cases, also refactoring to try make this coverage more obvious at a glance.

What changes are included in this PR?

This PR has a mix of new features (new casts supported) and refactoring.

New features:

  • Cast from List/LargeList to Utf8View
    • We supported casting to Utf8/LargeUtf8, but view was missing
  • Cast from ListView/LargeListView to string types
  • Cast between list view types when inner types differ
    • Previously we could cast ListView to LargeListView, but casting ListView<Int32> to ListView<Float32> was not supported; this adds that ability, which regular List arrays supported
  • Cast non-list types to ListView/LargeListView
  • Cast FixedSizeList to ListView/LargeListView
  • Cast List/LargeList to ListView/LargeListView when inner types differ
    • This again was something we supported, except we never accounted for the inner types differing; so fix to ensure we cast inner types
  • Cast List to LargeListView, LargeList to ListView, ListView to LargeList, LargeListView to List
    • These cross-offset casts were missing
  • Cast ListView/LargeListView to FixedSizeList

Refactors:

  • Consolidate arms in cast_with_options to organize the list casts together so it's easier to see we have coverage for casting between all list types
  • Condense testing code, trying to use existing downcast methods and array builders to reduce verbosity
  • Consolidate list view cast helper functions into the list cast helper functions file (arrow-cast/src/cast/list_view.rs merged into arrow-cast/src/cast/list.rs) since it's easier to track them together, especially with the cross list <-> listview cast functions

Are these changes tested?

Yes, added new tests.

Are there any user-facing changes?

No.

e.g. cast ListView(Int32) to ListView(Float32)
e.g. Int32 to ListView(Int32)

[1, 2, 3] -> [[1], [2], [3]]
e.g. FixedSizeList(Int32, 2) -> ListView(Float32)
e.g. List(Int32) -> ListView(Float32); previously we didn't account for
inner types differing so it would cast to ListView(Int32) only
@github-actions github-actions bot added the arrow Changes to the arrow crate label Jan 27, 2026
@Jefffrey Jefffrey marked this pull request as ready for review January 27, 2026 05:22
@Jefffrey
Copy link
Contributor Author

I would recommend reviewing commit by commit, as the commits more clearly show which changes are new features vs refactors, and each commit should be a manageable diff size to review.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve casting for listview types

1 participant