pub struct ShreddedSchemaBuilder {
root: VariantSchemaNode,
}Expand description
Builder for constructing a variant shredding schema.
The builder pattern makes it easy to incrementally define which fields
should be shredded and with what types. Fields are nullable by default; pass
a (data_type, nullable) pair or a FieldRef to control nullability.
[*] represents the shared element schema of a list, so items[*].id and
items[*].name describe fields on the same list element struct. Numeric
indexes refer to concrete list elements and are rejected by this builder.
§Example
use std::sync::Arc;
use arrow::datatypes::{DataType, Field, TimeUnit};
use parquet_variant::{VariantPath, VariantPathElement};
use parquet_variant_compute::ShreddedSchemaBuilder;
fn main() -> Result<(), arrow::error::ArrowError> {
// Define the shredding schema using the builder
let shredding_type = ShreddedSchemaBuilder::default()
// store the "time" field as a separate UTC timestamp
.with_path("time", (&DataType::Timestamp(TimeUnit::Nanosecond, Some("UTC".into())), true))?
// store hostname as non-nullable Utf8
.with_path("hostname", (&DataType::Utf8, false))?
// pass a FieldRef directly
.with_path(
"metadata.trace_id",
Arc::new(Field::new("trace_id", DataType::FixedSizeBinary(16), false)),
)?
// field name with a dot: use VariantPath to avoid splitting
.with_path(
VariantPath::from_iter([VariantPathElement::from("metrics.cpu")]),
&DataType::Float64,
)?
// [*] describes the shared schema for every element of a list
.with_path("items[*].id", &DataType::Int64)?
.build();
Ok(())
}
// The shredding_type can now be passed to shred_variant:
// let shredded = shred_variant(&input, &shredding_type)?;Fields§
§root: VariantSchemaNodeImplementations§
Source§impl ShreddedSchemaBuilder
impl ShreddedSchemaBuilder
Sourcepub fn with_path<'a, P, F>(self, path: P, field: F) -> Result<Self>
pub fn with_path<'a, P, F>(self, path: P, field: F) -> Result<Self>
Insert a typed path into the schema using dot notation (or any
[VariantPath] convertible).
The path uses dot notation to specify nested fields. For example, “a.b.c” will create a nested structure.
§Arguments
path- Anything convertible to [VariantPath] (e.g., a&str)field- Anything convertible viaIntoShreddingField(e.g.FieldRef,&DataType, or(&DataType, bool)to control nullability)
List schema paths must use [*]; numeric indexes return an error.
Trait Implementations§
Source§impl Clone for ShreddedSchemaBuilder
impl Clone for ShreddedSchemaBuilder
Auto Trait Implementations§
impl Freeze for ShreddedSchemaBuilder
impl RefUnwindSafe for ShreddedSchemaBuilder
impl Send for ShreddedSchemaBuilder
impl Sync for ShreddedSchemaBuilder
impl Unpin for ShreddedSchemaBuilder
impl UnsafeUnpin for ShreddedSchemaBuilder
impl UnwindSafe for ShreddedSchemaBuilder
Blanket Implementations§
impl<T> Allocation for T
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
Mutably borrows from an owned value. Read more