add native union type casting support#9544
Open
friendlymatthew wants to merge 1 commit intoapache:mainfrom
Open
add native union type casting support#9544friendlymatthew wants to merge 1 commit intoapache:mainfrom
friendlymatthew wants to merge 1 commit intoapache:mainfrom
Conversation
friendlymatthew
commented
Mar 12, 2026
Contributor
Author
friendlymatthew
left a comment
There was a problem hiding this comment.
self review
arrow-cast/src/cast/mod.rs
Outdated
Comment on lines
+1209
to
+1211
| (_, Union(_, _)) => Err(ArrowError::CastError(format!( | ||
| "Casting from {from_type} to {to_type} not supported" | ||
| ))), |
Contributor
Author
There was a problem hiding this comment.
This PR does not support casting scalar types into a Union type
It's not a feature that we currently need and will probably need more complex work to get it correct. Though, I think this is a cool/valid feature. I can file an issue if liked
Comment on lines
+2316
to
+2333
| let type_ids = array.type_ids().clone(); | ||
| let offsets = array.offsets().cloned(); | ||
|
|
||
| let new_children: Vec<ArrayRef> = from_fields | ||
| .iter() | ||
| .map(|(from_id, _from_field)| { | ||
| let (_, to_field) = to_fields | ||
| .iter() | ||
| .find(|(to_id, _)| *to_id == from_id) | ||
| .ok_or_else(|| { | ||
| ArrowError::CastError(format!( | ||
| "Cannot cast union: type_id {from_id} not found in target union" | ||
| )) | ||
| })?; | ||
| let child = array.child(from_id); | ||
| cast_with_options(child.as_ref(), to_field.data_type(), cast_options) | ||
| }) | ||
| .collect::<Result<_, _>>()?; |
Contributor
Author
There was a problem hiding this comment.
look ups like this can go from n^2 to nlogn if we implement #8937, since sorting by type_id will give us logn searching
26859a6 to
9c19cb1
Compare
9c19cb1 to
8dbe39f
Compare
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?
arrow-cast#9225Rationale for this change
This PR adds native support for casting Union arrays in the cast kernel. Previously,
can_cast_typesandcast_with_optionshad no handling for union types at all