pub struct LazyMaterializedBatch { /* private fields */ }Expand description
A lazy materialized batch that defers row materialization
This is the key abstraction for late materialization. It holds:
- Source data (either row-based or columnar)
- A selection vector indicating which rows are active
Rows are only materialized when explicitly requested, typically at the output boundary of query execution.
§Performance Benefits
- Memory: Only stores indices (4 bytes each) instead of full rows
- Cache: Selection vectors are cache-friendly during iteration
- Composition: Multiple operations can share source data via Arc
- Lazy Evaluation: Skips materialization for filtered rows
§Example
// Create a lazy batch from source data
let source = SourceData::Rows(Arc::new(rows));
let lazy_batch = LazyMaterializedBatch::new(source);
// Apply filter (just updates selection, no materialization)
let filtered = lazy_batch.filter(&filter_bitmap);
// Only materialize at output
let result_rows = filtered.materialize_selected(&[0, 2, 3])?; // Only these columnsImplementations§
Source§impl LazyMaterializedBatch
impl LazyMaterializedBatch
Sourcepub fn new(source: SourceData) -> Self
pub fn new(source: SourceData) -> Self
Create a new lazy batch from source data (selects all rows)
Sourcepub fn with_selection(source: SourceData, selection: SelectionVector) -> Self
pub fn with_selection(source: SourceData, selection: SelectionVector) -> Self
Create a new lazy batch with a specific selection
Sourcepub fn from_columnar(batch: ColumnarBatch) -> Self
pub fn from_columnar(batch: ColumnarBatch) -> Self
Create from columnar data
Sourcepub fn with_column_names(self, names: Vec<String>) -> Self
pub fn with_column_names(self, names: Vec<String>) -> Self
Set column names
Sourcepub fn selection(&self) -> &SelectionVector
pub fn selection(&self) -> &SelectionVector
Get the selection vector
Sourcepub fn column_names(&self) -> Option<&[String]>
pub fn column_names(&self) -> Option<&[String]>
Get column names if available
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Number of columns in the source
Sourcepub fn source_row_count(&self) -> usize
pub fn source_row_count(&self) -> usize
Total rows in source (before selection)
Sourcepub fn filter(&self, bitmap: &[bool]) -> Self
pub fn filter(&self, bitmap: &[bool]) -> Self
Apply a filter bitmap, returning a new lazy batch with refined selection
This is a lazy operation - it updates the selection vector without materializing any row data.
Sourcepub fn filter_with<F>(&self, predicate: F) -> Self
pub fn filter_with<F>(&self, predicate: F) -> Self
Apply a filter to the current selection
The predicate receives the source row index and should return true to keep the row.
Sourcepub fn intersect_selection(&self, other: &SelectionVector) -> Self
pub fn intersect_selection(&self, other: &SelectionVector) -> Self
Intersect selection with another selection vector
Sourcepub fn union_selection(&self, other: &SelectionVector) -> Self
pub fn union_selection(&self, other: &SelectionVector) -> Self
Union selection with another selection vector
Sourcepub fn materialize(&self) -> Result<Vec<Row>, ExecutorError>
pub fn materialize(&self) -> Result<Vec<Row>, ExecutorError>
Materialize all selected rows
This is typically called at the output boundary when results need to be returned to the caller.
Sourcepub fn materialize_columns(
&self,
column_indices: &[usize],
) -> Result<Vec<Row>, ExecutorError>
pub fn materialize_columns( &self, column_indices: &[usize], ) -> Result<Vec<Row>, ExecutorError>
Materialize only specific columns for selected rows
This is the most efficient output path - only materializes columns that appear in the final SELECT projection.
Sourcepub fn materialize_column(
&self,
column_idx: usize,
) -> Result<Vec<SqlValue>, ExecutorError>
pub fn materialize_column( &self, column_idx: usize, ) -> Result<Vec<SqlValue>, ExecutorError>
Materialize a single column for selected rows
Useful for extracting join keys or aggregation inputs.
Sourcepub fn get_selected_value(
&self,
selection_idx: usize,
column_idx: usize,
) -> Result<SqlValue, ExecutorError>
pub fn get_selected_value( &self, selection_idx: usize, column_idx: usize, ) -> Result<SqlValue, ExecutorError>
Get a single value from selected row
Sourcepub fn iter_indices(&self) -> impl Iterator<Item = u32> + '_
pub fn iter_indices(&self) -> impl Iterator<Item = u32> + '_
Iterate over selected row indices
Sourcepub fn remap_selection(&self, child_selection: &SelectionVector) -> Self
pub fn remap_selection(&self, child_selection: &SelectionVector) -> Self
Create a child batch with remapped selection
Used when chaining operations: if we filter a filtered result, we need to maintain the chain of selections.
Sourcepub fn column_array(&self, column_idx: usize) -> Option<&ColumnArray>
pub fn column_array(&self, column_idx: usize) -> Option<&ColumnArray>
Get the raw column array if source is columnar
Returns None if source is row-based.
Sourcepub fn is_columnar(&self) -> bool
pub fn is_columnar(&self) -> bool
Check if the source is columnar
Sourcepub fn to_columnar(&self) -> Result<LazyMaterializedBatch, ExecutorError>
pub fn to_columnar(&self) -> Result<LazyMaterializedBatch, ExecutorError>
Convert to columnar format if not already
This is useful when downstream operations benefit from columnar access.
Sourcepub fn selectivity(&self) -> f64
pub fn selectivity(&self) -> f64
Selectivity ratio
Trait Implementations§
Source§impl Clone for LazyMaterializedBatch
impl Clone for LazyMaterializedBatch
Source§fn clone(&self) -> LazyMaterializedBatch
fn clone(&self) -> LazyMaterializedBatch
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for LazyMaterializedBatch
impl RefUnwindSafe for LazyMaterializedBatch
impl Send for LazyMaterializedBatch
impl Sync for LazyMaterializedBatch
impl Unpin for LazyMaterializedBatch
impl UnwindSafe for LazyMaterializedBatch
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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