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 Forget for ShreddedSchemaBuilder
impl Freeze for ShreddedSchemaBuilderwhere
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
*const ArcInner<Field> is !null: Freeze,
PhantomData<ArcInner<Field>>: Freeze,
*const ArcInner<[Arc<Field>]> is !null: Freeze,
PhantomData<ArcInner<[Arc<Field>]>>: Freeze,
*const ArcInner<[(i8, Arc<Field>)]> is !null: Freeze,
PhantomData<ArcInner<[(i8, Arc<Field>)]>>: Freeze,
*const DataType is !null: Freeze,
PhantomData<DataType>: Freeze,
*const LeafNode<String, VariantSchemaNode> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(String, VariantSchemaNode)>>: Freeze,
*const VariantSchemaNode is !null: Freeze,
PhantomData<VariantSchemaNode>: Freeze,
impl Move for ShreddedSchemaBuilder
impl RefUnwindSafe for ShreddedSchemaBuilder
impl Send for ShreddedSchemaBuilder
impl Sync for ShreddedSchemaBuilder
impl Unpin for ShreddedSchemaBuilder
impl UnsafeUnpin for ShreddedSchemaBuilderwhere
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const ArcInner<Field> is !null: UnsafeUnpin,
PhantomData<ArcInner<Field>>: UnsafeUnpin,
*const ArcInner<[Arc<Field>]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[Arc<Field>]>>: UnsafeUnpin,
*const ArcInner<[(i8, Arc<Field>)]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[(i8, Arc<Field>)]>>: UnsafeUnpin,
*const DataType is !null: UnsafeUnpin,
PhantomData<DataType>: UnsafeUnpin,
*const LeafNode<String, VariantSchemaNode> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, VariantSchemaNode)>>: UnsafeUnpin,
*const VariantSchemaNode is !null: UnsafeUnpin,
PhantomData<VariantSchemaNode>: UnsafeUnpin,
impl UnwindSafe for ShreddedSchemaBuilderwhere
Arc<str>: UnwindSafe,
Arc<Field>: UnwindSafe,
Arc<[Arc<Field>]>: UnwindSafe,
Arc<[(i8, Arc<Field>)]>: UnwindSafe,
BoxRaw<DataType>: UnwindSafe,
BTreeMap<String, VariantSchemaNode>: UnwindSafe,
BoxRaw<VariantSchemaNode>: UnwindSafe,
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