Struct lance_core::datatypes::Schema
source · pub struct Schema {
pub fields: Vec<Field>,
pub metadata: HashMap<String, String>,
}
Expand description
Lance Schema.
Fields§
§fields: Vec<Field>
Top-level fields in the dataset.
metadata: HashMap<String, String>
Metadata of the schema
Implementations§
source§impl Schema
impl Schema
pub fn compare_with_options( &self, expected: &Self, options: &SchemaCompareOptions, ) -> bool
pub fn explain_difference( &self, expected: &Self, options: &SchemaCompareOptions, ) -> Option<String>
pub fn has_dictionary_types(&self) -> bool
pub fn check_compatible( &self, expected: &Self, options: &SchemaCompareOptions, ) -> Result<()>
sourcepub fn project<T: AsRef<str>>(&self, columns: &[T]) -> Result<Self>
pub fn project<T: AsRef<str>>(&self, columns: &[T]) -> Result<Self>
Project the columns over the schema.
let schema = Schema::from(...);
let projected = schema.project(&["col1", "col2.sub_col3.field4"])?;
sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Check that the top level fields don’t contain .
in their names
to distinguish from nested fields.
sourcepub fn intersection(&self, other: &Self) -> Result<Self>
pub fn intersection(&self, other: &Self) -> Result<Self>
Intersection between two Schema
.
sourcepub fn fields_pre_order(&self) -> impl Iterator<Item = &Field>
pub fn fields_pre_order(&self) -> impl Iterator<Item = &Field>
Iterates over the fields using a pre-order traversal
This is a DFS traversal where the parent is visited before its children
sourcepub fn project_by_ids(&self, column_ids: &[i32]) -> Self
pub fn project_by_ids(&self, column_ids: &[i32]) -> Self
Returns a new schema that only contains the fields in column_ids
.
This projection can filter out both top-level and nested fields
sourcepub fn project_by_schema<S: TryInto<Self, Error = Error>>(
&self,
projection: S,
) -> Result<Self>
pub fn project_by_schema<S: TryInto<Self, Error = Error>>( &self, projection: S, ) -> Result<Self>
Project the schema by another schema, and preserves field metadata, i.e., Field IDs.
Parameters
projection
: The schema to project by. Can bearrow_schema::Schema
orSchema
.
sourcepub fn exclude<T: TryInto<Self> + Debug>(&self, schema: T) -> Result<Self>
pub fn exclude<T: TryInto<Self> + Debug>(&self, schema: T) -> Result<Self>
Exclude the fields from other
Schema, and returns a new Schema.
sourcepub fn field(&self, name: &str) -> Option<&Field>
pub fn field(&self, name: &str) -> Option<&Field>
Get a field by name. Return None
if the field does not exist.
pub fn field_id(&self, column: &str) -> Result<i32>
pub fn top_level_field_ids(&self) -> Vec<i32>
pub fn field_ids(&self) -> Vec<i32>
sourcepub fn field_ancestry_by_id(&self, id: i32) -> Option<Vec<&Field>>
pub fn field_ancestry_by_id(&self, id: i32) -> Option<Vec<&Field>>
Get the sequence of fields from the root to the field with the given id.
pub fn mut_field_by_id(&mut self, id: impl Into<i32>) -> Option<&mut Field>
sourcepub fn max_field_id(&self) -> Option<i32>
pub fn max_field_id(&self) -> Option<i32>
Get the maximum field id in the schema.
Note: When working with Datasets, you should prefer [Manifest::max_field_id()] over this method. This method does not take into account the field IDs of dropped fields.
sourcepub fn set_dictionary(&mut self, batch: &RecordBatch) -> Result<()>
pub fn set_dictionary(&mut self, batch: &RecordBatch) -> Result<()>
Recursively attach set up dictionary values to the dictionary fields.
sourcepub fn set_field_id(&mut self, max_existing_id: Option<i32>)
pub fn set_field_id(&mut self, max_existing_id: Option<i32>)
Walk through the fields and assign a new field id to each field that does not have one (e.g. is set to -1)
If this schema is on an existing dataset, pass the result of
Manifest::max_field_id
to max_existing_id
. If for some reason that
id is lower than the maximum field id in this schema, the field IDs will
be reassigned starting from the maximum field id in this schema.
If this schema is not associated with a dataset, pass None
to
max_existing_id
. This is the same as passing Self::max_field_id().
sourcepub fn extend(&mut self, fields: &[ArrowField]) -> Result<()>
pub fn extend(&mut self, fields: &[ArrowField]) -> Result<()>
Create a new schema by adding fields to the end of this schema
Trait Implementations§
source§impl DeepSizeOf for Schema
impl DeepSizeOf for Schema
source§fn deep_size_of_children(&self, context: &mut Context) -> usize
fn deep_size_of_children(&self, context: &mut Context) -> usize
source§fn deep_size_of(&self) -> usize
fn deep_size_of(&self) -> usize
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<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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