UnionFields

Struct UnionFields 

pub struct UnionFields(Arc<[(i8, Arc<Field>)]>);
Expand description

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

Tuple Fields§

§0: Arc<[(i8, Arc<Field>)]>

Implementations§

§

impl UnionFields

pub fn empty() -> UnionFields

Create a new UnionFields with no fields

pub fn try_new<F, T>(type_ids: T, fields: F) -> Result<UnionFields, ArrowError>
where F: IntoIterator, <F as IntoIterator>::Item: Into<Arc<Field>>, 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());

pub fn from_fields<F>(fields: F) -> UnionFields
where F: IntoIterator, <F as IntoIterator>::Item: Into<Arc<Field>>,

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

pub fn try_from_fields<F>(fields: F) -> Result<UnionFields, ArrowError>
where F: IntoIterator, <F as IntoIterator>::Item: Into<Arc<Field>>,

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

pub fn new<F, T>(type_ids: T, fields: F) -> UnionFields
where F: IntoIterator, <F as IntoIterator>::Item: Into<Arc<Field>>, 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),
    ],
);

pub fn size(&self) -> usize

Return size of this instance in bytes.

pub fn len(&self) -> usize

Returns the number of fields in this UnionFields

pub fn is_empty(&self) -> bool

Returns true if this is empty

pub fn iter(&self) -> impl Iterator<Item = (i8, &Arc<Field>)>

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

pub fn get(&self, index: usize) -> Option<&(i8, Arc<Field>)>

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

pub fn find_by_type_id(&self, type_id: i8) -> Option<(i8, &Arc<Field>)>

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_field(&self, field: &Field) -> Option<(i8, &Arc<Field>)>

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§

§

impl Clone for UnionFields

§

fn clone(&self) -> UnionFields

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
§

impl Debug for UnionFields

§

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

Formats the value using the given formatter. Read more
§

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

§

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

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

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

§

fn from_iter<T>(iter: T) -> UnionFields
where T: IntoIterator<Item = (i8, Arc<Field>)>,

Creates a value from an iterator. Read more
§

impl Hash for UnionFields

§

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

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

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
§

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.

§

type Output = (i8, Arc<Field>)

The returned type after indexing.
§

fn index(&self, index: usize) -> &<UnionFields as Index<usize>>::Output

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

impl Ord for UnionFields

§

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

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

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

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

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

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

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

Restrict a value to a certain interval. Read more
§

impl PartialEq for UnionFields

§

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

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

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

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

impl PartialOrd for UnionFields

§

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§

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

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

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§

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

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

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

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

impl Serialize for UnionFields

§

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

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

impl Eq for UnionFields

§

impl StructuralPartialEq for UnionFields

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

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

§

impl<T> Ungil for T
where T: Send,