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: usizeThe number of rows in the final result.
state: ResultStateImplementations§
Source§impl ResultBuilder
impl ResultBuilder
Sourcefn new(data_type: &DataType, row_count: usize) -> Self
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.
Sourcefn add_branch_result(
&mut self,
row_indices: &ArrayRef,
value: ColumnarValue,
) -> Result<()>
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 arraysSourcefn add_partial_result(
&mut self,
row_indices: &ArrayRef,
row_values: ArrayData,
) -> Result<()>
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.
Sourcefn set_complete_result(&mut self, value: ColumnarValue) -> Result<()>
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.
Auto Trait Implementations§
impl Freeze for ResultBuilder
impl !RefUnwindSafe for ResultBuilder
impl Send for ResultBuilder
impl Sync for ResultBuilder
impl Unpin for ResultBuilder
impl !UnwindSafe for ResultBuilder
Blanket Implementations§
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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