pub struct Schema { /* private fields */ }
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.
Implementations
sourceimpl Schema
impl Schema
sourcepub fn new(fields: Vec<Field>) -> Self
pub fn new(fields: Vec<Field>) -> Self
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]);
sourcepub const fn new_with_metadata(
fields: Vec<Field>,
metadata: HashMap<String, String>
) -> Self
pub const fn new_with_metadata(
fields: Vec<Field>,
metadata: HashMap<String, String>
) -> Self
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>) -> Self
pub fn with_metadata(self, metadata: HashMap<String, String>) -> Self
Sets the metadata of this Schema
to be metadata
and returns self
sourcepub fn project(&self, indices: &[usize]) -> Result<Schema>
pub fn project(&self, indices: &[usize]) -> Result<Schema>
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 = Self>) -> Result<Self>
pub fn try_merge(schemas: impl IntoIterator<Item = Self>) -> Result<Self>
Merge schema into self if it is compatible. Struct fields will be merged recursively.
Example:
use arrow::datatypes::*;
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) -> &Vec<Field>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub const fn fields(&self) -> &Vec<Field>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Returns an immutable reference of the vector of Field
instances.
sourcepub fn field(&self, i: usize) -> &Field
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.
sourcepub fn field_with_name(&self, name: &str) -> Result<&Field>
pub fn field_with_name(&self, name: &str) -> Result<&Field>
Returns an immutable reference of a specific Field
instance selected by name.
sourcepub fn fields_with_dict_id(&self, dict_id: i64) -> Vec<&Field>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn fields_with_dict_id(&self, dict_id: i64) -> Vec<&Field>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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>
pub fn index_of(&self, name: &str) -> Result<usize>
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 from(json: &Value) -> Result<Self>
pub fn from(json: &Value) -> Result<Self>
Parse a Schema
definition from a JSON representation.
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. Here are the comparison rules:
self
andother
should contain the same number of fields- for every field
f
inother
, the field inself
with corresponding index should be a superset off
. - self.metadata is a superset of other.metadata
In other words, any record conforms to other
should also conform to self
.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl TryFrom<&'_ FFI_ArrowSchema> for Schema
impl TryFrom<&'_ FFI_ArrowSchema> for Schema
type Error = ArrowError
type Error = ArrowError
The type returned in the event of a conversion error.
sourcefn try_from(c_schema: &FFI_ArrowSchema) -> Result<Self>
fn try_from(c_schema: &FFI_ArrowSchema) -> Result<Self>
Performs the conversion.
sourceimpl TryFrom<&'_ Schema> for FFI_ArrowSchema
impl TryFrom<&'_ Schema> for FFI_ArrowSchema
sourceimpl TryFrom<Schema> for FFI_ArrowSchema
impl TryFrom<Schema> for FFI_ArrowSchema
impl Eq for Schema
impl StructuralEq for Schema
impl StructuralPartialEq for Schema
Auto Trait Implementations
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnwindSafe for Schema
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more