[Variant] add variant_to_arrow union builder - #10313
Conversation
Casting Variant to dense or sparse Union dispatches each value to the union field that most exactly represents its runtime type (lossless widening allowed, declaration order breaks ties). Null rows land in a Null-typed child if declared, otherwise the first child, since unions have no top-level null buffer. Co-Authored-By: Claude Fable 5 <[email protected]>
variant_to_arrow union buildervariant_to_arrow union builder
Jefffrey
left a comment
There was a problem hiding this comment.
disclaimer: this is kinda my first time looking at variant code 😅
| let null_child = fields | ||
| .iter() | ||
| .position(|(_, field)| field.data_type() == &DataType::Null) | ||
| .unwrap_or(0); |
There was a problem hiding this comment.
do we need to consider nullability of the field?
There was a problem hiding this comment.
I checked the existing Arrow union policy. UnionBuilder::append_null intentionally writes nulls into child arrays, while UnionBuilder::build still creates those child Fields with nullable = false. UnionArray::try_new does not validate field nullability, and union nullness is derived from the selected child array. Therefore the fallback does not need to select a nullable-declared field.
arrow-rs/arrow-array/src/builder/union_builder.rs
Lines 285 to 317 in e28fd0d
There was a problem hiding this comment.
the builder thing is a known issue:
i guess its one of those things which is a bit messy in the codebase as is 🤔
|
Thanks @Jefffrey 🙏 This is not the most |
|
@klion26 please you take a look 🙏 |
|
thanks @sdf-jkl |
Which issue does this PR close?
The last type to be supported by
variant_to_arrowcast.Rationale for this change
Check issue
What changes are included in this PR?
variant_to_arrowunion cast support + unit testsAre these changes tested?
Are there any user-facing changes?