Struct arrow::datatypes::Schema

source ·
pub struct Schema {
    pub fields: Fields,
    pub metadata: HashMap<String, String>,
}
Expand description

Describes the meta-data of an ordered sequence of relative types.

Note that this information is only part of the meta-data and not part of the physical memory layout.

Fields§

§fields: Fields§metadata: HashMap<String, String>

A map of key-value pairs containing additional meta data.

Implementations§

source§

impl Schema

source

pub fn empty() -> Schema

Creates an empty Schema

source

pub fn new(fields: impl Into<Fields>) -> Schema

Creates a new Schema from a sequence of Field values.

§Example
let field_a = Field::new("a", DataType::Int64, false);
let field_b = Field::new("b", DataType::Boolean, false);

let schema = Schema::new(vec![field_a, field_b]);
source

pub fn new_with_metadata( fields: impl Into<Fields>, metadata: HashMap<String, String> ) -> Schema

Creates a new Schema from a sequence of Field values and adds additional metadata in form of key value pairs.

§Example

let field_a = Field::new("a", DataType::Int64, false);
let field_b = Field::new("b", DataType::Boolean, false);

let mut metadata: HashMap<String, String> = HashMap::new();
metadata.insert("row_count".to_string(), "100".to_string());

let schema = Schema::new_with_metadata(vec![field_a, field_b], metadata);
source

pub fn with_metadata(self, metadata: HashMap<String, String>) -> Schema

Sets the metadata of this Schema to be metadata and returns self

source

pub fn project(&self, indices: &[usize]) -> Result<Schema, ArrowError>

Returns a new schema with only the specified columns in the new schema This carries metadata from the parent schema over as well

source

pub fn try_merge( schemas: impl IntoIterator<Item = Schema> ) -> Result<Schema, ArrowError>

Merge schema into self if it is compatible. Struct fields will be merged recursively.

Example:


let merged = Schema::try_merge(vec![
    Schema::new(vec![
        Field::new("c1", DataType::Int64, false),
        Field::new("c2", DataType::Utf8, false),
    ]),
    Schema::new(vec![
        Field::new("c1", DataType::Int64, true),
        Field::new("c2", DataType::Utf8, false),
        Field::new("c3", DataType::Utf8, false),
    ]),
]).unwrap();

assert_eq!(
    merged,
    Schema::new(vec![
        Field::new("c1", DataType::Int64, true),
        Field::new("c2", DataType::Utf8, false),
        Field::new("c3", DataType::Utf8, false),
    ]),
);
source

pub const fn fields(&self) -> &Fields

Returns an immutable reference of the vector of Field instances.

source

pub fn all_fields(&self) -> Vec<&Field>

Returns a vector with references to all fields (including nested fields)

source

pub fn field(&self, i: usize) -> &Field

Returns an immutable reference of a specific Field instance selected using an offset within the internal fields vector.

source

pub fn field_with_name(&self, name: &str) -> Result<&Field, ArrowError>

Returns an immutable reference of a specific Field instance selected by name.

source

pub fn fields_with_dict_id(&self, dict_id: i64) -> Vec<&Field>

Returns a vector of immutable references to all Field instances selected by the dictionary ID they use.

source

pub fn index_of(&self, name: &str) -> Result<usize, ArrowError>

Find the index of the column with the given name.

source

pub const fn metadata(&self) -> &HashMap<String, String>

Returns an immutable reference to the Map of custom metadata key-value pairs.

source

pub fn column_with_name(&self, name: &str) -> Option<(usize, &Field)>

Look up a column by name and return a immutable reference to the column along with its index.

source

pub fn contains(&self, other: &Schema) -> bool

Check to see if self is a superset of other schema.

In particular returns true if self.metadata is a superset of other.metadata and Fields::contains for self.fields and other.fields

In other words, any record that conforms to other should also conform to self.

Trait Implementations§

source§

impl Clone for Schema

source§

fn clone(&self) -> Schema

Returns a copy 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 Schema

source§

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

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

impl Display for Schema

source§

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

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

impl From<&Schema> for SchemaBuilder

source§

fn from(value: &Schema) -> SchemaBuilder

Converts to this type from the input type.
source§

impl From<Schema> for SchemaBuilder

source§

fn from(value: Schema) -> SchemaBuilder

Converts to this type from the input type.
source§

impl FromPyArrow for Schema

source§

fn from_pyarrow(value: &PyAny) -> PyResult<Self>

source§

impl Hash for Schema

source§

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

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 PartialEq for Schema

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl ToPyArrow for Schema

source§

impl TryFrom<&FFI_ArrowSchema> for Schema

§

type Error = ArrowError

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

fn try_from(c_schema: &FFI_ArrowSchema) -> Result<Schema, ArrowError>

Performs the conversion.
source§

impl TryFrom<&Schema> for FFI_ArrowSchema

§

type Error = ArrowError

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

fn try_from(schema: &Schema) -> Result<FFI_ArrowSchema, ArrowError>

Performs the conversion.
source§

impl TryFrom<Schema> for FFI_ArrowSchema

§

type Error = ArrowError

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

fn try_from(schema: Schema) -> Result<FFI_ArrowSchema, ArrowError>

Performs the conversion.
source§

impl Eq for Schema

source§

impl StructuralPartialEq for Schema

Auto Trait Implementations§

§

impl Freeze for Schema

§

impl RefUnwindSafe for Schema

§

impl Send for Schema

§

impl Sync for Schema

§

impl Unpin for Schema

§

impl UnwindSafe for Schema

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

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

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

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

source§

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

Compare self to key and return true if they are equal.
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> IntoPyArrow for T
where T: ToPyArrow,

source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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> Allocation for T
where T: RefUnwindSafe + Send + Sync,

source§

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