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
A sequence of fields that describe the schema.
metadata: HashMap<String, String>
A map of key-value pairs containing additional meta data.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn new_with_metadata(
fields: impl Into<Fields>,
metadata: HashMap<String, String>,
) -> Schema
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);
Sourcepub fn with_metadata(self, metadata: HashMap<String, String>) -> Schema
pub fn with_metadata(self, metadata: HashMap<String, String>) -> Schema
Sets the metadata of this Schema
to be metadata
and returns self
Sourcepub fn project(&self, indices: &[usize]) -> Result<Schema, ArrowError>
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
Sourcepub fn try_merge(
schemas: impl IntoIterator<Item = Schema>,
) -> Result<Schema, ArrowError>
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),
]),
);
Sourcepub const fn fields(&self) -> &Fields
pub const fn fields(&self) -> &Fields
Returns an immutable reference of the vector of Field
instances.
Sourcepub fn flattened_fields(&self) -> Vec<&Field>
pub fn flattened_fields(&self) -> Vec<&Field>
Returns a vector with references to all fields (including nested fields)
§Example
use std::sync::Arc;
use arrow_schema::{DataType, Field, Fields, Schema};
let f1 = Arc::new(Field::new("a", DataType::Boolean, false));
let f2_inner = Arc::new(Field::new("b_inner", DataType::Int8, false));
let f2 = Arc::new(Field::new("b", DataType::List(f2_inner.clone()), false));
let f3_inner1 = Arc::new(Field::new("c_inner1", DataType::Int8, false));
let f3_inner2 = Arc::new(Field::new("c_inner2", DataType::Int8, false));
let f3 = Arc::new(Field::new(
"c",
DataType::Struct(vec![f3_inner1.clone(), f3_inner2.clone()].into()),
false
));
let mut schema = Schema::new(vec![
f1.clone(), f2.clone(), f3.clone()
]);
assert_eq!(
schema.flattened_fields(),
vec![
f1.as_ref(),
f2.as_ref(),
f2_inner.as_ref(),
f3.as_ref(),
f3_inner1.as_ref(),
f3_inner2.as_ref()
]
);
Sourcepub fn all_fields(&self) -> Vec<&Field>
👎Deprecated since 52.2.0: Use flattened_fields
instead
pub fn all_fields(&self) -> Vec<&Field>
flattened_fields
insteadReturns a vector with references to all fields (including nested fields)
Sourcepub fn field_with_name(&self, name: &str) -> Result<&Field, ArrowError>
pub fn field_with_name(&self, name: &str) -> Result<&Field, ArrowError>
Returns an immutable reference of a specific Field
instance selected by name.
Sourcepub fn fields_with_dict_id(&self, dict_id: i64) -> Vec<&Field>
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.
Sourcepub fn index_of(&self, name: &str) -> Result<usize, ArrowError>
pub fn index_of(&self, name: &str) -> Result<usize, ArrowError>
Find the index of the column with the given name.
Sourcepub const fn metadata(&self) -> &HashMap<String, String>
pub const fn metadata(&self) -> &HashMap<String, String>
Returns an immutable reference to the Map of custom metadata key-value pairs.
Sourcepub fn column_with_name(&self, name: &str) -> Option<(usize, &Field)>
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.
Sourcepub fn contains(&self, other: &Schema) -> bool
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 From<&Schema> for SchemaBuilder
impl From<&Schema> for SchemaBuilder
Source§fn from(value: &Schema) -> SchemaBuilder
fn from(value: &Schema) -> SchemaBuilder
Source§impl From<Schema> for SchemaBuilder
impl From<Schema> for SchemaBuilder
Source§fn from(value: Schema) -> SchemaBuilder
fn from(value: Schema) -> SchemaBuilder
Source§impl SchemaExt for Schema
impl SchemaExt for Schema
Source§impl ToDFSchema for Schema
impl ToDFSchema for Schema
Source§fn to_dfschema(self) -> Result<DFSchema, DataFusionError>
fn to_dfschema(self) -> Result<DFSchema, DataFusionError>
Source§fn to_dfschema_ref(self) -> Result<Arc<DFSchema>, DataFusionError>
fn to_dfschema_ref(self) -> Result<Arc<DFSchema>, DataFusionError>
impl Eq for Schema
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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