Skip to main content

PlanBuilder

Struct PlanBuilder 

Source
pub struct PlanBuilder(/* private fields */);
Available on crate feature declarative-plans only.
Expand description

A Plan under construction. See the module docs.

Implementations§

Source§

impl PlanBuilder

Source

pub fn scan_parquet( files: impl IntoIterator<Item = impl Into<ScanFile>>, file_constant_columns: &[&str], schema: impl Into<SchemaRef>, ) -> DeltaResult<Self>

A Parquet scan source over files producing rows matching schema.

file_constant_columns names the per-file-constant output columns (see ScanParquet); pass &[] when there are none. An empty files yields the absent relation.

Produces an error when any file’s constant count differs from file_constant_columns’s length, or a file_constant_columns entry is absent from schema.

Source

pub fn scan_json( files: impl IntoIterator<Item = impl Into<ScanFile>>, file_constant_columns: &[&str], schema: impl Into<SchemaRef>, ) -> DeltaResult<Self>

A newline-delimited JSON scan source over files producing rows matching schema. See ScanJson. Exhibits same behaviour as Self::scan_parquet.

Source

pub fn values( schema: impl Into<SchemaRef>, rows: Vec<Vec<Scalar>>, ) -> DeltaResult<Self>

Inline literal rows. See Values for the row encoding. Empty rows yields the absent relation.

Produces an error when any row’s width differs from schema’s top-level field count.

§Example
let schema = Arc::new(StructType::try_new([StructField::not_null("id", DataType::INTEGER)])?);
let plan = PlanBuilder::values(schema, vec![vec![1.into()], vec![2.into()]])?.build()?;
Source

pub fn filter(self, predicate: impl Into<PredicateRef>) -> DeltaResult<Self>

Keep rows where predicate holds. Output schema is unchanged. See Filter.

Produces an error when predicate references a column absent from the input schema.

§Example
let schema = Arc::new(StructType::try_new([StructField::not_null("id", DataType::INTEGER)])?);
let plan = PlanBuilder::values(schema, vec![vec![1.into()], vec![2.into()]])?
    .filter(col!("id").is_not_null())?
    .build()?;
Source

pub fn project( self, expr: impl Into<ExpressionRef>, schema: impl Into<SchemaRef>, ) -> DeltaResult<Self>

Project self through expr into rows of the caller-declared schema. expr must be a struct constructor / patch matching schema. See Project.

Produces an error when expr references a column absent from the input schema. References inside a StructPatch are validated by ProjectionStructPatchBuilder when the patch is

§Example
let input = Arc::new(StructType::try_new([
    StructField::not_null("id", DataType::INTEGER),
    StructField::nullable("name", DataType::STRING),
])?);
let out = Arc::new(StructType::try_new([StructField::not_null("id", DataType::INTEGER)])?);
// Keep only `id`.
let plan = PlanBuilder::values(input, vec![vec![1.into(), "a".into()]])?
    .project(Expression::struct_from([col!("id")]), out)?
    .build()?;
Source

pub fn project_patch( self, patch: impl FnOnce(ProjectionStructPatchBuilder<'_>) -> ProjectionStructPatchBuilder<'_>, ) -> DeltaResult<Self>

Project self by editing its columns. edit receives a ProjectionStructPatchBuilder rooted at self’s schema and records field edits (replace/drop/append); the lowered patch and the resulting output schema feed the Project node together. See Project.

Produces an error when the patch fails to build – e.g. a replaced or dropped field is absent from the input schema, or a nested path does not resolve.

Source

pub fn load(self, load: Load) -> DeltaResult<Self>

Read data files named by self’s rows. Output schema is load.schema. See Load.

Produces an error when a file_meta/deletion-vector column is absent from the input schema, or a file_constant_columns entry is absent from the input (its broadcast source) or from load.schema (the output).

Source

pub fn aggregate( self, aggregate: impl TryInto<Aggregate, Error = Error>, ) -> DeltaResult<Self>

Aggregate self into aggregate (build one with Aggregate::group_by). The output schema is the group keys followed by the aggregate columns. See Aggregate.

Over an absent input the result is group-arity dependent: a grouped aggregate yields zero groups and so is absent; a global aggregate (no group keys) still yields one row, so it aggregates an empty Values input and lets the engine produce that row.

Produces an error when building aggregate fails: a group key or an aggregate’s operand column is absent from its input schema, or two output columns would share a name.

Source

pub fn aggregate_by( self, keys: impl CollectInto<Vec<ColumnName>>, aggs: impl FnOnce(AggregateBuilder) -> AggregateBuilder, ) -> DeltaResult<Self>

Aggregate self, grouped by keys. aggs receives an AggregateBuilder rooted at self’s schema and adds the aggregate columns (see AggregateBuilder::max, …). Mirrors Self::aggregate but spares the caller from naming the input schema, just as Self::project_patch does for Self::project. See Aggregate.

Produces an error under the same conditions as Self::aggregate.

§Example
let schema = Arc::new(StructType::try_new([
    StructField::not_null("id", DataType::INTEGER),
    StructField::nullable("version", DataType::LONG),
])?);
// Latest `version` per `id`.
let plan = PlanBuilder::values(schema, vec![vec![1.into(), 7i64.into()]])?
    .aggregate_by([column_name!("id")], |a| a.max(column_name!("version")))?
    .build()?;
Source

pub fn semi_join( self, build: PlanBuilder, probe_keys: impl IntoIterator<Item = ColumnName>, build_keys: impl IntoIterator<Item = ColumnName>, ) -> DeltaResult<Self>

Semi join: emit the self (probe) rows that have a match in build on the join keys. Output schema mirrors self. Inputs are recorded as [probe, build]. See SemiJoin.

Keys are columns (e.g. column_name!), matched pairwise.

Produces an error when the probe and build key counts differ, or a probe/build key is absent from its input schema.

§Example
let schema = Arc::new(StructType::try_new([StructField::not_null("id", DataType::INTEGER)])?);
let probe = PlanBuilder::values(Arc::clone(&schema), vec![vec![1.into()], vec![2.into()]])?;
let allow = PlanBuilder::values(schema, vec![vec![2.into()]])?;
// Probe rows whose `id` appears in `allow`.
let plan = probe.semi_join(allow, [column_name!("id")], [column_name!("id")])?.build()?;
Source

pub fn anti_join( self, build: PlanBuilder, probe_keys: impl IntoIterator<Item = ColumnName>, build_keys: impl IntoIterator<Item = ColumnName>, ) -> DeltaResult<Self>

Anti join: emit the self (probe) rows that have no match in build on the join keys. An inverted SemiJoin; otherwise as Self::semi_join.

Source

pub fn union_all( inputs: impl IntoIterator<Item = PlanBuilder>, ) -> DeltaResult<Self>

Unordered bag union of inputs into a UnionAll. All inputs must share the same schema; absent inputs are dropped, and a lone present input is forwarded unchanged.

Produces an error when inputs is empty, or two inputs have differing schemas.

§Example
let schema = Arc::new(StructType::try_new([StructField::not_null("id", DataType::INTEGER)])?);
let a = PlanBuilder::values(Arc::clone(&schema), vec![vec![1.into()]])?;
let b = PlanBuilder::values(schema, vec![vec![2.into()]])?;
let plan = PlanBuilder::union_all([a, b])?.build()?;
Source

pub fn build(&self) -> DeltaResult<Plan>

Linearize the DAG reachable from self into a Plan. An absent relation builds to a single empty Values node carrying its schema, so the result is always a runnable plan.

Source

pub fn build_opt(&self) -> DeltaResult<Option<Plan>>

Like Self::build, but yields None for an absent relation instead of an empty plan.

Trait Implementations§

Source§

impl Clone for PlanBuilder

Source§

fn clone(&self) -> PlanBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PlanBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any + Send + Sync,

Source§

fn any_ref(&self) -> &(dyn Any + Sync + Send + 'static)

Obtains a dyn Any reference to the object: Read more
Source§

fn as_any(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Obtains an Arc<dyn Any> reference to the object: Read more
Source§

fn into_any(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts the object to Box<dyn Any>: Read more
Source§

fn type_name(&self) -> &'static str

Convenient wrapper for 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> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> FoldWithOption for T

Source§

fn fold_with<U>(self, opt: Option<U>, f: impl FnOnce(T, U) -> T) -> T

Available on crate feature internal-api only.
Applies an optional fold operation f to self if opt is Some; otherwise returns self. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<KernelType, ArrowType> TryIntoArrow<ArrowType> for KernelType
where ArrowType: TryFromKernel<KernelType>,

Source§

fn try_into_arrow(self) -> Result<ArrowType, ArrowError>

Available on crate feature arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.
Source§

impl<KernelType, ArrowType> TryIntoKernel<KernelType> for ArrowType
where KernelType: TryFromArrow<ArrowType>,

Source§

fn try_into_kernel(self) -> Result<KernelType, ArrowError>

Available on crate feature arrow-conversion and (crate features arrow-conversion or declarative-plans or default-engine-base) only.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more