@@ -25,8 +25,8 @@ use arrow_select::union_extract::union_extract;
2525
2626use super :: CastOptions ;
2727
28- // this is used during variant selection to prefer a "close" type over a distant cast
29- // for example: when targeting Utf8View, a Utf8 variant is preferred over Int32 despite both being castable
28+ // this is used during child array selection to prefer a "close" type over a distant cast
29+ // for example: when targeting Utf8View, a Utf8 child is preferred over Int32 despite both being castable
3030fn same_type_family ( a : & DataType , b : & DataType ) -> bool {
3131 use DataType :: * ;
3232 matches ! (
@@ -61,7 +61,7 @@ fn same_type_family(a: &DataType, b: &DataType) -> bool {
6161/// nulls, which can conflict with non-nullable inner fields
6262///
6363/// Each pass greedily picks the first matching field by type_id order
64- pub ( crate ) fn resolve_variant < ' a > (
64+ pub ( crate ) fn resolve_child_array < ' a > (
6565 fields : & ' a UnionFields ,
6666 target_type : & DataType ,
6767) -> Option < & ' a FieldRef > {
@@ -74,7 +74,7 @@ pub(crate) fn resolve_variant<'a>(
7474 . find ( |( _, f) | same_type_family ( f. data_type ( ) , target_type) )
7575 } )
7676 . or_else ( || {
77- // skip nested types in pass 3 — union extraction introduces nulls,
77+ // skip nested types in pass 3 because union extraction introduces nulls,
7878 // and casting nullable arrays to nested types like List/Struct/Map can fail
7979 // when inner fields are non-nullable.
8080 if target_type. is_nested ( ) {
@@ -90,8 +90,8 @@ pub(crate) fn resolve_variant<'a>(
9090/// Extracts the best-matching child array from a [`UnionArray`] for a given target type,
9191/// and casts it to that type.
9292///
93- /// Rows where a different variant is active become NULL.
94- /// If no variant matches, returns a null array .
93+ /// Rows where a different child array is active become NULL.
94+ /// If no child array matches, returns an error .
9595///
9696/// # Example
9797///
@@ -120,7 +120,7 @@ pub(crate) fn resolve_variant<'a>(
120120/// )
121121/// .unwrap();
122122///
123- /// // extract the Utf8 variant and cast to Utf8View
123+ /// // extract the Utf8 child array and cast to Utf8View
124124/// let result = union_extract_by_type(&union, &DataType::Utf8View, &CastOptions::default()).unwrap();
125125/// assert_eq!(result.data_type(), &DataType::Utf8View);
126126/// assert!(result.is_null(0)); // Int32 row -> NULL
@@ -137,7 +137,7 @@ pub fn union_extract_by_type(
137137 _ => unreachable ! ( "union_extract_by_type called on non-union array" ) ,
138138 } ;
139139
140- let Some ( field) = resolve_variant ( fields, target_type) else {
140+ let Some ( field) = resolve_child_array ( fields, target_type) else {
141141 return Err ( ArrowError :: CastError ( format ! (
142142 "cannot cast Union with fields {} to {}" ,
143143 fields
@@ -182,7 +182,7 @@ mod tests {
182182 }
183183
184184 // pass 1: exact type match.
185- // Union(Int32, Utf8) targeting Utf8 — the Utf8 variant matches exactly.
185+ // Union(Int32, Utf8) targeting Utf8. The Utf8 child matches exactly.
186186 // Int32 rows become NULL. tested for both sparse and dense.
187187 #[ test]
188188 fn test_exact_type_match ( ) {
@@ -237,7 +237,7 @@ mod tests {
237237 }
238238
239239 // pass 2: same type family match.
240- // Union(Int32, Utf8) targeting Utf8View — no exact match, but Utf8 and Utf8View
240+ // Union(Int32, Utf8) targeting Utf8View. No exact match, but Utf8 and Utf8View
241241 // are in the same family. picks the Utf8 variant and casts to Utf8View.
242242 // this is the bug that motivated this work: without pass 2, pass 3 would
243243 // greedily pick Int32 (since can_cast_types(Int32, Utf8View) is true).
0 commit comments