Struct ShreddedSchemaBuilder
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§
§impl ShreddedSchemaBuilder
impl ShreddedSchemaBuilder
pub fn new() -> ShreddedSchemaBuilder
pub fn new() -> ShreddedSchemaBuilder
Create a new empty schema builder.
pub fn with_path<'a, P, F>(
self,
path: P,
field: F,
) -> Result<ShreddedSchemaBuilder, ArrowError>where
P: TryInto<VariantPath<'a>>,
<P as TryInto<VariantPath<'a>>>::Error: Debug,
F: IntoShreddingField,
pub fn with_path<'a, P, F>(
self,
path: P,
field: F,
) -> Result<ShreddedSchemaBuilder, ArrowError>where
P: TryInto<VariantPath<'a>>,
<P as TryInto<VariantPath<'a>>>::Error: Debug,
F: IntoShreddingField,
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 toVariantPath(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.
pub fn build(self) -> DataType
pub fn build(self) -> DataType
Build the final [DataType].
Trait Implementations§
§impl Clone for ShreddedSchemaBuilder
impl Clone for ShreddedSchemaBuilder
§fn clone(&self) -> ShreddedSchemaBuilder
fn clone(&self) -> ShreddedSchemaBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more