LazyMaterializedBatch

Struct LazyMaterializedBatch 

Source
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

  1. Memory: Only stores indices (4 bytes each) instead of full rows
  2. Cache: Selection vectors are cache-friendly during iteration
  3. Composition: Multiple operations can share source data via Arc
  4. 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 columns

Implementations§

Source§

impl LazyMaterializedBatch

Source

pub fn new(source: SourceData) -> Self

Create a new lazy batch from source data (selects all rows)

Source

pub fn with_selection(source: SourceData, selection: SelectionVector) -> Self

Create a new lazy batch with a specific selection

Source

pub fn from_rows(rows: Vec<Row>) -> Self

Create from row-based data

Source

pub fn from_columnar(batch: ColumnarBatch) -> Self

Create from columnar data

Source

pub fn with_column_names(self, names: Vec<String>) -> Self

Set column names

Source

pub fn source(&self) -> &SourceData

Get the source data

Source

pub fn selection(&self) -> &SelectionVector

Get the selection vector

Source

pub fn column_names(&self) -> Option<&[String]>

Get column names if available

Source

pub fn len(&self) -> usize

Number of selected (active) rows

Source

pub fn is_empty(&self) -> bool

Check if no rows are selected

Source

pub fn column_count(&self) -> usize

Number of columns in the source

Source

pub fn source_row_count(&self) -> usize

Total rows in source (before selection)

Source

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.

Source

pub fn filter_with<F>(&self, predicate: F) -> Self
where F: Fn(usize) -> bool,

Apply a filter to the current selection

The predicate receives the source row index and should return true to keep the row.

Source

pub fn intersect_selection(&self, other: &SelectionVector) -> Self

Intersect selection with another selection vector

Source

pub fn union_selection(&self, other: &SelectionVector) -> Self

Union selection with another selection vector

Source

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.

Source

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.

Source

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.

Source

pub fn get_selected_value( &self, selection_idx: usize, column_idx: usize, ) -> Result<SqlValue, ExecutorError>

Get a single value from selected row

Source

pub fn iter_indices(&self) -> impl Iterator<Item = u32> + '_

Iterate over selected row indices

Source

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.

Source

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.

Source

pub fn is_columnar(&self) -> bool

Check if the source is columnar

Source

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.

Source

pub fn selectivity(&self) -> f64

Selectivity ratio

Trait Implementations§

Source§

impl Clone for LazyMaterializedBatch

Source§

fn clone(&self) -> LazyMaterializedBatch

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LazyMaterializedBatch

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,