This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 558f7446fe Add getters to `UnionFields` (#8895)
558f7446fe is described below
commit 558f7446fe62e85083b10a49d187524f45c74db5
Author: Matthew Kim <[email protected]>
AuthorDate: Mon Nov 24 16:11:19 2025 -0500
Add getters to `UnionFields` (#8895)
# Rationale for this change
This PR adds convenience getter methods to the `UnionFields` api. It's
very common to find a specific union field by `FieldRef` or type id
---
arrow-schema/src/fields.rs | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/arrow-schema/src/fields.rs b/arrow-schema/src/fields.rs
index b280961522..0d351356b9 100644
--- a/arrow-schema/src/fields.rs
+++ b/arrow-schema/src/fields.rs
@@ -396,6 +396,18 @@ impl UnionFields {
self.0.iter().map(|(id, f)| (*id, f))
}
+ /// Searches for a field by its type id, returning the type id and field
reference if found.
+ /// Returns `None` if no field with the given type id exists.
+ pub fn find_by_type_id(&self, type_id: i8) -> Option<(i8, &FieldRef)> {
+ self.iter().find(|&(i, _)| i == type_id)
+ }
+
+ /// Searches for a field by value equality, returning its type id and
reference if found.
+ /// Returns `None` if no matching field exists in this [`UnionFields`].
+ pub fn find_by_field(&self, field: &Field) -> Option<(i8, &FieldRef)> {
+ self.iter().find(|&(_, f)| f.as_ref() == field)
+ }
+
/// Merge this field into self if it is compatible.
///
/// See [`Field::try_merge`]