pub(crate) fn resolve_child_array<'a>(
fields: &'a UnionFields,
target_type: &DataType,
) -> Option<&'a FieldRef>Expand description
Selects the best-matching child array from a [UnionArray] for a given target type
The goal is to find the source field whose type is closest to the target, so that the subsequent cast is as lossless as possible. The heuristic uses three passes with decreasing specificity:
- Exact match: field type equals the target type.
- Same type family: field and target belong to the same logical family
(e.g.
Utf8andUtf8Vieware both strings). This avoids a greedy cross-family cast in pass 3 (e.g. pickingInt32overUtf8when the target isUtf8View, sincecan_cast_types(Int32, Utf8View)is true) - Castable:
can_cast_typesreports the field can be cast to the target Nested target types are skipped here because union extraction introduces nulls, which can conflict with non-nullable inner fields
Each pass greedily picks the first matching field by type_id order