pub struct StructType { /* private fields */ }Expand description
A struct is used to represent both the top-level schema of the table as well as struct columns that contain nested columns.
Implementations§
Source§impl StructType
impl StructType
Sourcepub fn try_new(
fields: impl IntoIterator<Item = StructField>,
) -> DeltaResult<Self>
pub fn try_new( fields: impl IntoIterator<Item = StructField>, ) -> DeltaResult<Self>
Creates a new StructType from the given fields.
Returns an error if:
- the schema contains duplicate field names (case-insensitive; Delta column names are case-insensitive per the protocol)
- the schema contains duplicate metadata columns
- the schema contains nested metadata columns
Sourcepub fn try_from_results<E: Into<Error>>(
fields: impl IntoIterator<Item = Result<StructField, E>>,
) -> DeltaResult<Self>
pub fn try_from_results<E: Into<Error>>( fields: impl IntoIterator<Item = Result<StructField, E>>, ) -> DeltaResult<Self>
Creates a new StructType from a fallible iterator of fields.
This constructor collects all fields from the iterator, returning the first error
encountered, or a new StructType if all fields are successfully collected and validated.
pub fn builder() -> StructTypeBuilder
Sourcepub fn new_unchecked(fields: impl IntoIterator<Item = StructField>) -> Self
Available on crate feature internal-api only.
pub fn new_unchecked(fields: impl IntoIterator<Item = StructField>) -> Self
internal-api only.Creates a new StructType from the given fields without validating them.
This should only be used when you are sure that the fields are valid.
Refer to StructType::try_new for more details on the validation checks.
Sourcepub fn project_as_struct(
&self,
names: &[impl AsRef<str>],
) -> DeltaResult<StructType>
pub fn project_as_struct( &self, names: &[impl AsRef<str>], ) -> DeltaResult<StructType>
Gets a StructType containing StructFields of the given names. The order of fields in
the returned schema will match the order passed to this function, which can be different
from this order in this schema. Returns an Err if a specified field doesn’t exist.
Sourcepub fn project(&self, names: &[impl AsRef<str>]) -> DeltaResult<SchemaRef>
pub fn project(&self, names: &[impl AsRef<str>]) -> DeltaResult<SchemaRef>
Gets a SchemaRef containing StructFields of the given names. The order of fields in
the returned schema will match the order passed to this function, which can be different
from this order in this schema. Returns an Err if a specified field doesn’t exist.
Sourcepub fn add(
&self,
fields: impl IntoIterator<Item = StructField>,
) -> DeltaResult<Self>
pub fn add( &self, fields: impl IntoIterator<Item = StructField>, ) -> DeltaResult<Self>
Adds fields to this StructType, returning a new StructType.
Sourcepub fn add_metadata_column(
&self,
name: impl Into<String>,
spec: MetadataColumnSpec,
) -> DeltaResult<Self>
pub fn add_metadata_column( &self, name: impl Into<String>, spec: MetadataColumnSpec, ) -> DeltaResult<Self>
Adds a predefined metadata column to this StructType, returning a new StructType.
Sourcepub fn index_of(&self, name: impl AsRef<str>) -> Option<usize>
pub fn index_of(&self, name: impl AsRef<str>) -> Option<usize>
Returns the index of the field with the given name, or None if not found.
Sourcepub fn index_of_metadata_column(
&self,
spec: &MetadataColumnSpec,
) -> Option<&usize>
pub fn index_of_metadata_column( &self, spec: &MetadataColumnSpec, ) -> Option<&usize>
Returns the index of the metadata column with the given spec, or None if not found.
Sourcepub fn contains(&self, name: impl AsRef<str>) -> bool
pub fn contains(&self, name: impl AsRef<str>) -> bool
Checks if the StructType contains a field with the specified name.
Sourcepub fn contains_metadata_column(&self, spec: &MetadataColumnSpec) -> bool
pub fn contains_metadata_column(&self, spec: &MetadataColumnSpec) -> bool
Checks if the StructType contains a metadata column with the given spec.
Sourcepub fn field(&self, name: impl AsRef<str>) -> Option<&StructField>
pub fn field(&self, name: impl AsRef<str>) -> Option<&StructField>
Gets the field with the given name.
Sourcepub fn field_at<'a>(&'a self, col: &ColumnName) -> DeltaResult<&'a StructField>
pub fn field_at<'a>(&'a self, col: &ColumnName) -> DeltaResult<&'a StructField>
Retrieves the nested field named by the given column path.
Returns an error if the path is empty, a field is not found, or an intermediate field is not a struct type.
Sourcepub fn contains_col(&self, col: impl CollectInto<ColumnName>) -> bool
pub fn contains_col(&self, col: impl CollectInto<ColumnName>) -> bool
Checks whether this schema contains the field at the given column path.
Sourcepub fn visit_fields_of_path<'a>(
&'a self,
col: &ColumnName,
visit_field: impl FnMut(&'a StructField),
) -> DeltaResult<()>
Available on crate feature internal-api only.
pub fn visit_fields_of_path<'a>( &'a self, col: &ColumnName, visit_field: impl FnMut(&'a StructField), ) -> DeltaResult<()>
internal-api only.Visits all fields along the given column path.
Returns an error if the path is empty, a field is not found, or an intermediate field is not a struct type.
Sourcepub fn fields_of_path<'a>(
&'a self,
col: &ColumnName,
) -> DeltaResult<Vec<&'a StructField>>
Available on crate feature internal-api only.
pub fn fields_of_path<'a>( &'a self, col: &ColumnName, ) -> DeltaResult<Vec<&'a StructField>>
internal-api only.Resolves a column path through nested structs, returning references to all
StructFields along the path. The last element is the leaf field.
Each element of the path must resolve to a field in the current struct. All intermediate (non-leaf) fields must be struct types.
Returns an error if the path is empty, a field is not found, or an intermediate field is not a struct type.
Sourcepub fn field_with_index(
&self,
name: impl AsRef<str>,
) -> Option<(usize, &StructField)>
pub fn field_with_index( &self, name: impl AsRef<str>, ) -> Option<(usize, &StructField)>
Gets the field with the given name and its index.
Sourcepub fn field_at_index(&self, index: usize) -> Option<&StructField>
pub fn field_at_index(&self, index: usize) -> Option<&StructField>
Gets the field at the given index.
Sourcepub fn fields(
&self,
) -> impl ExactSizeIterator<Item = &StructField> + DoubleEndedIterator + FusedIterator
pub fn fields( &self, ) -> impl ExactSizeIterator<Item = &StructField> + DoubleEndedIterator + FusedIterator
Gets a reference to all the fields in this struct type.
Sourcepub fn into_fields(
self,
) -> impl ExactSizeIterator<Item = StructField> + DoubleEndedIterator + FusedIterator
pub fn into_fields( self, ) -> impl ExactSizeIterator<Item = StructField> + DoubleEndedIterator + FusedIterator
Gets an iterator over all the fields in this struct type.
Sourcepub fn field_at_path<'a>(&'a self, path: &[String]) -> &'a StructField
Available on crate features test-utils only.
pub fn field_at_path<'a>(&'a self, path: &[String]) -> &'a StructField
test-utils only.Walk a pre-segmented column path through this schema and return the leaf field.
path is the path’s individual name segments (one per nesting level), already split by
the caller. Lookup at each level is case-insensitive. The Delta protocol uses . as the
dotted-path separator at the API surface, but field_at_path itself does not split –
callers typically pass ColumnName::path(),
which yields the segments directly.
Panics if any segment is missing or an intermediate field is not a struct. Intended for use in test assertions.
§Example
// Schema:
// id: INTEGER not null
// address: STRUCT { city: STRING not null, zip: STRING }
let path = vec!["address".to_string(), "city".to_string()];
let city = schema.field_at_path(&path);
assert_eq!(city.name(), "city");
assert!(!city.is_nullable());Sourcepub fn field_names(&self) -> impl ExactSizeIterator<Item = &String>
pub fn field_names(&self) -> impl ExactSizeIterator<Item = &String>
Gets all the field names in this struct type in the order they are defined.
Sourcepub fn num_fields(&self) -> usize
pub fn num_fields(&self) -> usize
Gets the number of fields in this struct type.
Sourcepub fn total_struct_fields(&self) -> usize
Available on crate feature internal-api only.
pub fn total_struct_fields(&self) -> usize
internal-api only.Recursively counts all StructField nodes in this schema tree.
This includes nested struct fields (inside Struct, Array, and Map types) but does not
count Array/Map containers themselves. This matches the traversal pattern used by
assign_column_mapping_metadata when assigning column IDs, so the result equals the
expected delta.columnMapping.maxColumnId for a newly created table.
Sourcepub fn metadata_column(&self, spec: &MetadataColumnSpec) -> Option<&StructField>
pub fn metadata_column(&self, spec: &MetadataColumnSpec) -> Option<&StructField>
Gets a reference to the metadata column with the given spec.
Sourcepub fn metadata_columns(&self) -> impl Iterator<Item = &StructField>
pub fn metadata_columns(&self) -> impl Iterator<Item = &StructField>
Gets an iterator over all the metadata columns in this struct type.
Sourcepub fn leaves<'s>(
&self,
own_name: impl Into<Option<&'s str>>,
) -> ColumnNamesAndTypes
Available on crate feature internal-api only.
pub fn leaves<'s>( &self, own_name: impl Into<Option<&'s str>>, ) -> ColumnNamesAndTypes
internal-api only.Extracts the name and type of all leaf columns, in schema order. Caller should pass Some
own_name if this schema is embedded in a larger struct (e.g. add.*) and None if the
schema is a top-level result (e.g. *).
NOTE: This method only traverses through StructType fields; MapType and ArrayType
fields are considered leaves even if they contain StructType entries/elements.
Sourcepub fn make_physical(
&self,
column_mapping_mode: ColumnMappingMode,
) -> DeltaResult<Self>
Available on crate feature internal-api only.
pub fn make_physical( &self, column_mapping_mode: ColumnMappingMode, ) -> DeltaResult<Self>
internal-api only.Applies physical name mappings to this field. If the column_mapping_mode is
ColumnMappingMode::Id, then each StructField will have its parquet field id in the
ColumnMetadataKey::ParquetFieldId metadata field.
Uses a single transformer so duplicate column mapping IDs are detected across all fields in this struct, not just within each field’s subtree.
Sourcepub fn with_fields_filtered(
&self,
predicate: impl Fn(&StructField) -> bool,
) -> DeltaResult<Self>
pub fn with_fields_filtered( &self, predicate: impl Fn(&StructField) -> bool, ) -> DeltaResult<Self>
Returns a new StructType containing only the top-level fields for which predicate
returns true. This does not recurse into nested StructType fields.
Sourcepub fn with_fields_filtered_nonempty(
&self,
predicate: impl Fn(&StructField) -> bool,
) -> DeltaResult<Option<Self>>
pub fn with_fields_filtered_nonempty( &self, predicate: impl Fn(&StructField) -> bool, ) -> DeltaResult<Option<Self>>
Returns an optional StructType containing only the top-level fields for which
predicate returns true.
This is a convenience wrapper around StructType::with_fields_filtered for callers
that treat an empty top-level struct as “no schema”.
Trait Implementations§
Source§impl Clone for StructType
impl Clone for StructType
Source§impl Debug for StructType
impl Debug for StructType
Source§impl<'de> Deserialize<'de> for StructType
impl<'de> Deserialize<'de> for StructType
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Self: Sized,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Self: Sized,
Source§impl Display for StructType
impl Display for StructType
impl Eq for StructType
Source§impl From<&StructType> for StructType
Available on crate feature declarative-plans only.
impl From<&StructType> for StructType
declarative-plans only.Source§fn from(struct_type: &StructType) -> Self
fn from(struct_type: &StructType) -> Self
Source§impl From<StructType> for DataType
impl From<StructType> for DataType
Source§fn from(struct_type: StructType) -> Self
fn from(struct_type: StructType) -> Self
Source§impl IntoIterator for StructType
impl IntoIterator for StructType
Source§impl<'a> IntoIterator for &'a StructType
impl<'a> IntoIterator for &'a StructType
Source§impl PartialEq for StructType
impl PartialEq for StructType
Source§impl Serialize for StructType
impl Serialize for StructType
impl StructuralPartialEq for StructType
Source§impl TryFrom<StructType> for StructType
Available on crate feature declarative-plans only.
impl TryFrom<StructType> for StructType
declarative-plans only.Source§fn try_from(proto: StructType) -> DeltaResult<Self>
fn try_from(proto: StructType) -> DeltaResult<Self>
Source§impl TryFromArrow<&Schema> for StructType
Available on crate feature arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.
impl TryFromArrow<&Schema> for StructType
arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.fn try_from_arrow(arrow_schema: &ArrowSchema) -> Result<Self, ArrowError>
Source§impl TryFromArrow<Arc<Schema>> for StructType
Available on crate feature arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.
impl TryFromArrow<Arc<Schema>> for StructType
arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.fn try_from_arrow(arrow_schema: ArrowSchemaRef) -> Result<Self, ArrowError>
Source§impl TryFromKernel<&StructType> for Schema
Available on crate feature arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.
impl TryFromKernel<&StructType> for Schema
arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.fn try_from_kernel(s: &StructType) -> Result<Self, ArrowError>
Auto Trait Implementations§
impl Freeze for StructType
impl RefUnwindSafe for StructType
impl Send for StructType
impl Sync for StructType
impl Unpin for StructType
impl UnsafeUnpin for StructType
impl UnwindSafe for StructType
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> AsAny for T
impl<T> AsAny for T
Source§fn any_ref(&self) -> &(dyn Any + Sync + Send + 'static)
fn any_ref(&self) -> &(dyn Any + Sync + Send + 'static)
dyn Any reference to the object: Read moreSource§fn as_any(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ
fn as_any(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ
Arc<dyn Any> reference to the object: Read moreSource§fn into_any(self: Box<T>) -> Box<dyn Any + Sync + Send>
fn into_any(self: Box<T>) -> Box<dyn Any + Sync + Send>
Box<dyn Any>: Read moreSource§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
std::any::type_name, since Any does not provide it and
Any::type_id is useless as a debugging aid (its Debug is just a mess of hex digits).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§impl<I, T> CollectInto<T> for I
impl<I, T> CollectInto<T> for I
Source§fn collect_into(self) -> T
fn collect_into(self) -> T
internal-api only.Timpl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DynPartialEq for T
impl<T> DynPartialEq for T
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FoldWithOption for T
impl<T> FoldWithOption for T
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.
Source§impl<KernelType, ArrowType> TryIntoArrow<ArrowType> for KernelTypewhere
ArrowType: TryFromKernel<KernelType>,
impl<KernelType, ArrowType> TryIntoArrow<ArrowType> for KernelTypewhere
ArrowType: TryFromKernel<KernelType>,
Source§fn try_into_arrow(self) -> Result<ArrowType, ArrowError>
fn try_into_arrow(self) -> Result<ArrowType, ArrowError>
arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.Source§impl<KernelType, ArrowType> TryIntoKernel<KernelType> for ArrowTypewhere
KernelType: TryFromArrow<ArrowType>,
impl<KernelType, ArrowType> TryIntoKernel<KernelType> for ArrowTypewhere
KernelType: TryFromArrow<ArrowType>,
Source§fn try_into_kernel(self) -> Result<KernelType, ArrowError>
fn try_into_kernel(self) -> Result<KernelType, ArrowError>
arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.