pub struct UnionFields(Arc<[(i8, FieldRef)]>);Expand description
A cheaply cloneable, owned collection of FieldRef and their corresponding type ids
Tuple Fields§
§0: Arc<[(i8, FieldRef)]>Implementations§
Source§impl UnionFields
impl UnionFields
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create a new UnionFields with no fields
Sourcepub fn new<F, T>(type_ids: T, fields: F) -> Self
pub fn new<F, T>(type_ids: T, fields: F) -> Self
Create a new UnionFields from a Fields and array of type_ids
See https://arrow.apache.org/docs/format/Columnar.html#union-layout
use arrow_schema::{DataType, Field, UnionFields};
// Create a new UnionFields with type id mapping
// 1 -> DataType::UInt8
// 3 -> DataType::Utf8
UnionFields::new(
vec![1, 3],
vec![
Field::new("field1", DataType::UInt8, false),
Field::new("field3", DataType::Utf8, false),
],
);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of fields in this UnionFields
Sourcepub fn iter(&self) -> impl Iterator<Item = (i8, &FieldRef)> + '_
pub fn iter(&self) -> impl Iterator<Item = (i8, &FieldRef)> + '_
Returns an iterator over the fields and type ids in this UnionFields
Sourcepub fn get(&self, index: usize) -> Option<&(i8, FieldRef)>
pub fn get(&self, index: usize) -> Option<&(i8, FieldRef)>
Returns a reference to the field at the given index, or None if out of bounds.
This is a safe alternative to direct indexing via [].
§Example
use arrow_schema::{DataType, Field, UnionFields};
let fields = UnionFields::new(
vec![1, 3],
vec![
Field::new("field1", DataType::UInt8, false),
Field::new("field3", DataType::Utf8, false),
],
);
assert!(fields.get(0).is_some());
assert!(fields.get(1).is_some());
assert!(fields.get(2).is_none());Sourcepub fn find_by_type_id(&self, type_id: i8) -> Option<(i8, &FieldRef)>
pub fn find_by_type_id(&self, type_id: i8) -> Option<(i8, &FieldRef)>
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.
Sourcepub fn find_by_field(&self, field: &Field) -> Option<(i8, &FieldRef)>
pub fn find_by_field(&self, field: &Field) -> Option<(i8, &FieldRef)>
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.
Sourcepub(crate) fn try_merge(&mut self, other: &Self) -> Result<(), ArrowError>
pub(crate) fn try_merge(&mut self, other: &Self) -> Result<(), ArrowError>
Merge this field into self if it is compatible.
See Field::try_merge
Trait Implementations§
Source§impl Clone for UnionFields
impl Clone for UnionFields
Source§fn clone(&self) -> UnionFields
fn clone(&self) -> UnionFields
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UnionFields
impl Debug for UnionFields
Source§impl<'de> Deserialize<'de> for UnionFields
impl<'de> Deserialize<'de> for UnionFields
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl FromIterator<(i8, Arc<Field>)> for UnionFields
impl FromIterator<(i8, Arc<Field>)> for UnionFields
Source§impl Hash for UnionFields
impl Hash for UnionFields
Source§impl Index<usize> for UnionFields
Allows direct indexing into UnionFields to access fields by position.
impl Index<usize> for UnionFields
Allows direct indexing into UnionFields to access fields by position.
§Panics
Panics if the index is out of bounds. Note that UnionFields supports
a maximum of 128 fields, as type IDs are represented as i8 values.
For a non-panicking alternative, use UnionFields::get.