Struct datafusion::common::DFSchema

source ·
pub struct DFSchema { /* private fields */ }
Expand description

DFSchema wraps an Arrow schema and adds relation names.

The schema may hold the fields across multiple tables. Some fields may be qualified and some unqualified. A qualified field is a field that has a relation name associated with it.

Unqualified fields must be unique not only amongst themselves, but also must have a distinct name from any qualified field names. This allows finding a qualified field by name to be possible, so long as there aren’t multiple qualified fields with the same name.

There is an alias to Arc<DFSchema> named DFSchemaRef.

§Creating qualified schemas

Use DFSchema::try_from_qualified_schema to create a qualified schema from an Arrow schema.

use datafusion_common::{DFSchema, Column};
use arrow_schema::{DataType, Field, Schema};

let arrow_schema = Schema::new(vec![
   Field::new("c1", DataType::Int32, false),
]);

let df_schema = DFSchema::try_from_qualified_schema("t1", &arrow_schema).unwrap();
let column = Column::from_qualified_name("t1.c1");
assert!(df_schema.has_column(&column));

// Can also access qualified fields with unqualified name, if it's unambiguous
let column = Column::from_qualified_name("c1");
assert!(df_schema.has_column(&column));

§Creating unqualified schemas

Create an unqualified schema using TryFrom:

use datafusion_common::{DFSchema, Column};
use arrow_schema::{DataType, Field, Schema};

let arrow_schema = Schema::new(vec![
   Field::new("c1", DataType::Int32, false),
]);

let df_schema = DFSchema::try_from(arrow_schema).unwrap();
let column = Column::new_unqualified("c1");
assert!(df_schema.has_column(&column));

§Converting back to Arrow schema

Use the Into trait to convert DFSchema into an Arrow schema:

use datafusion_common::{DFSchema, DFField};
use arrow_schema::Schema;
use std::collections::HashMap;

let df_schema = DFSchema::new_with_metadata(vec![
   DFField::new_unqualified("c1", arrow::datatypes::DataType::Int32, false),
], HashMap::new()).unwrap();
let schema = Schema::from(df_schema);
assert_eq!(schema.fields().len(), 1);

Implementations§

source§

impl DFSchema

source

pub fn empty() -> DFSchema

Creates an empty DFSchema

source

pub fn new_with_metadata( fields: Vec<DFField>, metadata: HashMap<String, String> ) -> Result<DFSchema, DataFusionError>

Create a new DFSchema

source

pub fn try_from_qualified_schema<'a>( qualifier: impl Into<TableReference<'a>>, schema: &Schema ) -> Result<DFSchema, DataFusionError>

Create a DFSchema from an Arrow schema and a given qualifier

To create a schema from an Arrow schema without a qualifier, use DFSchema::try_from.

source

pub fn with_functional_dependencies( self, functional_dependencies: FunctionalDependencies ) -> Result<DFSchema, DataFusionError>

Assigns functional dependencies.

source

pub fn join(&self, schema: &DFSchema) -> Result<DFSchema, DataFusionError>

Create a new schema that contains the fields from this schema followed by the fields from the supplied schema. An error will be returned if there are duplicate field names.

source

pub fn merge(&mut self, other_schema: &DFSchema)

Modify this schema by appending the fields from the supplied schema, ignoring any duplicate fields.

source

pub fn fields(&self) -> &Vec<DFField>

Get a list of fields

source

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

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

source

pub fn index_of_column_by_name( &self, qualifier: Option<&TableReference<'_>>, name: &str ) -> Result<Option<usize>, DataFusionError>

source

pub fn index_of_column(&self, col: &Column) -> Result<usize, DataFusionError>

Find the index of the column with the given qualifier and name

source

pub fn is_column_from_schema( &self, col: &Column ) -> Result<bool, DataFusionError>

Check if the column is in the current schema

source

pub fn field_with_name( &self, qualifier: Option<&TableReference<'_>>, name: &str ) -> Result<&DFField, DataFusionError>

Find the field with the given name

source

pub fn fields_with_qualified( &self, qualifier: &TableReference<'_> ) -> Vec<&DFField>

Find all fields having the given qualifier

source

pub fn fields_indices_with_qualified( &self, qualifier: &TableReference<'_> ) -> Vec<usize>

Find all fields indices having the given qualifier

source

pub fn fields_with_unqualified_name(&self, name: &str) -> Vec<&DFField>

Find all fields match the given name

source

pub fn field_with_unqualified_name( &self, name: &str ) -> Result<&DFField, DataFusionError>

Find the field with the given name

source

pub fn field_with_qualified_name( &self, qualifier: &TableReference<'_>, name: &str ) -> Result<&DFField, DataFusionError>

Find the field with the given qualified name

source

pub fn field_from_column( &self, column: &Column ) -> Result<&DFField, DataFusionError>

Find the field with the given qualified column

source

pub fn has_column_with_unqualified_name(&self, name: &str) -> bool

Find if the field exists with the given name

source

pub fn has_column_with_qualified_name( &self, qualifier: &TableReference<'_>, name: &str ) -> bool

Find if the field exists with the given qualified name

source

pub fn has_column(&self, column: &Column) -> bool

Find if the field exists with the given qualified column

source

pub fn matches_arrow_schema(&self, arrow_schema: &Schema) -> bool

Check to see if unqualified field names matches field names in Arrow schema

source

pub fn check_arrow_schema_type_compatible( &self, arrow_schema: &Schema ) -> Result<(), DataFusionError>

Check to see if fields in 2 Arrow schemas are compatible

source

pub fn logically_equivalent_names_and_types(&self, other: &DFSchema) -> bool

Returns true if the two schemas have the same qualified named fields with logically equivalent data types. Returns false otherwise.

Use DFSchema::equivalent_names_and_types for stricter semantic type equivalence checking.

source

pub fn equivalent_names_and_types(&self, other: &DFSchema) -> bool

Returns true if the two schemas have the same qualified named fields with the same data types. Returns false otherwise.

This is a specialized version of Eq that ignores differences in nullability and metadata.

Use DFSchema::logically_equivalent_names_and_types for a weaker logical type checking, which for example would consider a dictionary encoded UTF8 array to be equivalent to a plain UTF8 array.

source

pub fn strip_qualifiers(self) -> DFSchema

Strip all field qualifier in schema

source

pub fn replace_qualifier( self, qualifier: impl Into<TableReference<'static>> ) -> DFSchema

Replace all field qualifier with new value in schema

source

pub fn field_names(&self) -> Vec<String>

Get list of fully-qualified field names in this schema

source

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

Get metadata of this schema

source

pub fn functional_dependencies(&self) -> &FunctionalDependencies

Get functional dependencies

Trait Implementations§

source§

impl Clone for DFSchema

source§

fn clone(&self) -> DFSchema

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 DFSchema

source§

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

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

impl Display for DFSchema

source§

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

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

impl ExprSchema for DFSchema

source§

fn nullable(&self, col: &Column) -> Result<bool, DataFusionError>

Is this column reference nullable?
source§

fn data_type(&self, col: &Column) -> Result<&DataType, DataFusionError>

What is the datatype of this column?
source§

fn metadata( &self, col: &Column ) -> Result<&HashMap<String, String>, DataFusionError>

Returns the column’s optional metadata.
source§

fn data_type_and_nullable( &self, col: &Column ) -> Result<(&DataType, bool), DataFusionError>

Return the coulmn’s datatype and nullability
source§

impl From<&DFSchema> for Schema

source§

fn from(df_schema: &DFSchema) -> Schema

Convert DFSchema reference into a Schema

source§

impl From<DFSchema> for Arc<Schema>

source§

fn from(df_schema: DFSchema) -> Arc<Schema>

Converts to this type from the input type.
source§

impl From<DFSchema> for Schema

source§

fn from(df_schema: DFSchema) -> Schema

Convert DFSchema into a Schema

source§

impl Hash for DFSchema

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 DFSchema

source§

fn eq(&self, other: &DFSchema) -> 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 TryFrom<Schema> for DFSchema

Create a DFSchema from an Arrow schema

§

type Error = DataFusionError

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

fn try_from( schema: Schema ) -> Result<DFSchema, <DFSchema as TryFrom<Schema>>::Error>

Performs the conversion.
source§

impl Eq for DFSchema

source§

impl StructuralPartialEq for DFSchema

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<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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

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