Skip to main content

resolve_child_array

Function resolve_child_array 

Source
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:

  1. Exact match: field type equals the target type.
  2. Same type family: field and target belong to the same logical family (e.g. Utf8 and Utf8View are both strings). This avoids a greedy cross-family cast in pass 3 (e.g. picking Int32 over Utf8 when the target is Utf8View, since can_cast_types(Int32, Utf8View) is true)
  3. Castable:can_cast_types reports 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