UnionFields

Struct UnionFields 

Source
pub struct UnionFields(/* private fields */);
Expand description

A cheaply cloneable, owned collection of FieldRef and their corresponding type ids

Implementations§

Source§

impl UnionFields

Source

pub fn empty() -> Self

Create a new UnionFields with no fields

Source

pub fn try_new<F, T>(type_ids: T, fields: F) -> Result<Self, ArrowError>
where F: IntoIterator, F::Item: Into<FieldRef>, T: IntoIterator<Item = i8>,

Create a new UnionFields from a Fields and array of type_ids

See https://arrow.apache.org/docs/format/Columnar.html#union-layout

§Errors

This function returns an error if:

  • Any type_id appears more than once (duplicate type ids)
  • The type_ids are duplicated
§Examples
use arrow_schema::{DataType, Field, UnionFields};
// Create a new UnionFields with type id mapping
// 1 -> DataType::UInt8
// 3 -> DataType::Utf8
let result = UnionFields::try_new(
    vec![1, 3],
    vec![
        Field::new("field1", DataType::UInt8, false),
        Field::new("field3", DataType::Utf8, false),
    ],
);
assert!(result.is_ok());

// This will fail due to duplicate type ids
let result = UnionFields::try_new(
    vec![1, 1],
    vec![
        Field::new("field1", DataType::UInt8, false),
        Field::new("field2", DataType::Utf8, false),
    ],
);
assert!(result.is_err());
Source

pub fn from_fields<F>(fields: F) -> Self
where F: IntoIterator, F::Item: Into<FieldRef>,

Create a new UnionFields from a collection of fields with automatically assigned type IDs starting from 0.

The type IDs are assigned in increasing order: 0, 1, 2, 3, etc.

See https://arrow.apache.org/docs/format/Columnar.html#union-layout

§Panics

Panics if the number of fields exceeds 127 (the maximum value for i8 type IDs).

If you want to avoid panics, use UnionFields::try_from_fields instead, which returns a Result.

§Examples
use arrow_schema::{DataType, Field, UnionFields};
// Create a new UnionFields with automatic type id assignment
// 0 -> DataType::UInt8
// 1 -> DataType::Utf8
let union_fields = UnionFields::from_fields(vec![
    Field::new("field1", DataType::UInt8, false),
    Field::new("field2", DataType::Utf8, false),
]);
assert_eq!(union_fields.len(), 2);
Source

pub fn try_from_fields<F>(fields: F) -> Result<Self, ArrowError>
where F: IntoIterator, F::Item: Into<FieldRef>,

Create a new UnionFields from a collection of fields with automatically assigned type IDs starting from 0.

The type IDs are assigned in increasing order: 0, 1, 2, 3, etc.

This is the non-panicking version of UnionFields::from_fields.

See https://arrow.apache.org/docs/format/Columnar.html#union-layout

§Errors

Returns an error if the number of fields exceeds 127 (the maximum value for i8 type IDs).

§Examples
use arrow_schema::{DataType, Field, UnionFields};
// Create a new UnionFields with automatic type id assignment
// 0 -> DataType::UInt8
// 1 -> DataType::Utf8
let result = UnionFields::try_from_fields(vec![
    Field::new("field1", DataType::UInt8, false),
    Field::new("field2", DataType::Utf8, false),
]);
assert!(result.is_ok());
assert_eq!(result.unwrap().len(), 2);

// This will fail with too many fields
let many_fields: Vec<_> = (0..200)
    .map(|i| Field::new(format!("field{}", i), DataType::Int32, false))
    .collect();
let result = UnionFields::try_from_fields(many_fields);
assert!(result.is_err());
Source

pub fn new<F, T>(type_ids: T, fields: F) -> Self
where F: IntoIterator, F::Item: Into<FieldRef>, T: IntoIterator<Item = i8>,

👎Deprecated since 57.0.0: Use try_new instead

Create a new UnionFields from a Fields and array of type_ids

See https://arrow.apache.org/docs/format/Columnar.html#union-layout

§Deprecated

Use UnionFields::try_new instead. This method panics on invalid input, while try_new returns a Result.

§Panics

Panics if any type_id appears more than once (duplicate type ids).

use arrow_schema::{DataType, Field, UnionFields};
// Create a new UnionFields with type id mapping
// 1 -> DataType::UInt8
// 3 -> DataType::Utf8
UnionFields::try_new(
    vec![1, 3],
    vec![
        Field::new("field1", DataType::UInt8, false),
        Field::new("field3", DataType::Utf8, false),
    ],
);
Source

pub fn size(&self) -> usize

Return size of this instance in bytes.

Source

pub fn len(&self) -> usize

Returns the number of fields in this UnionFields

Source

pub fn is_empty(&self) -> bool

Returns true if this is empty

Source

pub fn iter(&self) -> impl Iterator<Item = (i8, &FieldRef)> + '_

Returns an iterator over the fields and type ids in this UnionFields

Source

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());
Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for UnionFields

Source§

fn clone(&self) -> UnionFields

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnionFields

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for UnionFields

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromIterator<(i8, Arc<Field>)> for UnionFields

Source§

fn from_iter<T: IntoIterator<Item = (i8, FieldRef)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for UnionFields

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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.

Source§

type Output = (i8, Arc<Field>)

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Ord for UnionFields

Source§

fn cmp(&self, other: &UnionFields) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for UnionFields

Source§

fn eq(&self, other: &UnionFields) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for UnionFields

Source§

fn partial_cmp(&self, other: &UnionFields) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for UnionFields

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for UnionFields

Source§

impl StructuralPartialEq for UnionFields

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,