ResultBuilder

Struct ResultBuilder 

Source
struct ResultBuilder {
    data_type: DataType,
    row_count: usize,
    state: ResultState,
}
Expand description

A builder for constructing result arrays for CASE expressions.

Rather than building a monolithic array containing all results, it maintains a set of partial result arrays and a mapping that indicates for each row which partial array contains the result value for that row.

On finish(), the builder will merge all partial results into a single array if necessary. If all rows evaluated to the same array, that array can be returned directly without any merging overhead.

Fields§

§data_type: DataType§row_count: usize

The number of rows in the final result.

§state: ResultState

Implementations§

Source§

impl ResultBuilder

Source

fn new(data_type: &DataType, row_count: usize) -> Self

Creates a new ResultBuilder that will produce arrays of the given data type.

The row_count parameter indicates the number of rows in the final result.

Source

fn add_branch_result( &mut self, row_indices: &ArrayRef, value: ColumnarValue, ) -> Result<()>

Adds a result for one branch of the case expression.

row_indices should be a [UInt32Array] containing [RecordBatch] relative row indices for which value contains result values.

If value is a scalar, the scalar value will be used as the value for each row in row_indices.

If value is an array, the values from the array and the indices from row_indices will be processed pairwise. The lengths of value and row_indices must match.

The diagram below shows a situation where a when expression matched rows 1 and 4 of the record batch. The then expression produced the value array [A, D]. After adding this result, the result array will have been added to partial arrays and partial indices will have been updated at indexes 1 and 4.

 ┌─────────┐     ┌─────────┐┌───────────┐                            ┌─────────┐┌───────────┐
 │    C    │     │ 0: None ││┌ 0 ──────┐│                            │ 0: None ││┌ 0 ──────┐│
 ├─────────┤     ├─────────┤││    A    ││                            ├─────────┤││    A    ││
 │    D    │     │ 1: None ││└─────────┘│                            │ 1:  2   ││└─────────┘│
 └─────────┘     ├─────────┤│┌ 1 ──────┐│   add_branch_result(       ├─────────┤│┌ 1 ──────┐│
  matching       │ 2:  0   │││    B    ││     row indices,           │ 2:  0   │││    B    ││
'then' values    ├─────────┤│└─────────┘│     value                  ├─────────┤│└─────────┘│
                 │ 3: None ││           │   )                        │ 3: None ││┌ 2 ──────┐│
 ┌─────────┐     ├─────────┤│           │ ─────────────────────────▶ ├─────────┤││    C    ││
 │    1    │     │ 4: None ││           │                            │ 4:  2   ││├─────────┤│
 ├─────────┤     ├─────────┤│           │                            ├─────────┤││    D    ││
 │    4    │     │ 5:  1   ││           │                            │ 5:  1   ││└─────────┘│
 └─────────┘     └─────────┘└───────────┘                            └─────────┘└───────────┘
row indices        partial     partial                                 partial     partial
                   indices     arrays                                  indices     arrays
Source

fn add_partial_result( &mut self, row_indices: &ArrayRef, row_values: ArrayData, ) -> Result<()>

Adds a partial result array.

This method adds the given array data as a partial result and updates the index mapping to indicate that the specified rows should take their values from this array. The partial results will be merged into a single array when finish() is called.

Source

fn set_complete_result(&mut self, value: ColumnarValue) -> Result<()>

Sets a result that applies to all rows.

This is an optimization for cases where all rows evaluate to the same result. When a complete result is set, the builder will return it directly from finish() without any merging overhead.

Source

fn finish(self) -> Result<ColumnarValue>

Finishes building the result and returns the final array.

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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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, 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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,