Skip to main content

SpillBuffer

Struct SpillBuffer 

Source
pub struct SpillBuffer { /* private fields */ }
Expand description

Append-only batch buffer with an encoded-byte memory budget.

The budget is exact for the serialized representation and does not claim to be the Rust allocator’s resident-byte accounting. At most one incoming or decoded batch can itself be larger than the budget; successful pushes do not retain such an oversized batch in memory.

Implementations§

Source§

impl SpillBuffer

Source

pub fn new(budget_bytes: usize) -> Self

Source

pub fn new_in(budget_bytes: usize, directory: impl Into<PathBuf>) -> Self

Create a buffer whose temporary spill file will be placed in directory.

File creation is deferred until the first spill. This is primarily useful when an engine has a dedicated temporary-data volume.

Source

pub fn unbounded() -> Self

Source

pub fn push(&mut self, batch: Batch) -> ExecResult<bool>

Append a batch, spilling automatically when required by the byte budget.

Returns true if this push wrote one or more batches to disk. If disk creation, encoding, or writing fails, the new batch and all earlier batches remain owned by the buffer and the error is returned.

Source

pub fn encoded_size(batch: &Batch) -> ExecResult<usize>

Exact byte count used for budget accounting, including the record length prefix written to disk.

Source

pub fn rows(&self) -> usize

Total buffered rows, including rows already written to disk.

Source

pub fn in_memory_rows(&self) -> usize

Rows currently retained in memory.

Source

pub fn in_memory_bytes(&self) -> usize

Exact encoded bytes currently retained in memory.

Source

pub fn budget_bytes(&self) -> usize

Source

pub fn over_budget(&self) -> bool

Source

pub fn has_spilled(&self) -> bool

Source

pub fn spilled_rows(&self) -> usize

Source

pub fn spilled_batches(&self) -> usize

Source

pub fn spilled_bytes(&self) -> usize

Source

pub fn spill_path(&self) -> Option<&Path>

Path of the live spill file, if one has been created.

The path is diagnostic only and becomes invalid as soon as the buffer or the drain iterator that owns the file is dropped.

Source

pub fn spill_if_over_budget(&mut self) -> ExecResult<bool>

Flush all pending in-memory batches when the byte budget is exceeded.

Returns true when batches were written. A failed append is rolled back to the previous file length and the pending batches remain in memory, so callers never observe a silent partial spill.

Source

pub fn spill_pending(&mut self) -> ExecResult<bool>

Force all pending in-memory batches to disk regardless of the budget.

This is useful at a blocking-operator phase boundary. It returns false when there is nothing pending.

Source

pub fn reader(&self) -> ExecResult<SpillReader<'_>>

Open a repeatable streaming reader without consuming this buffer.

Spilled batches are decoded one at a time. The in-memory tail is cloned one batch at a time only when the reader reaches it.

Source

pub fn read_rows(&self) -> ExecResult<SpillRows<SpillReader<'_>>>

Open a repeatable physical-row stream without collecting all batches.

Source

pub fn drain(&mut self) -> ExecResult<SpillDrain>

Drain buffered batches in their original input order.

The returned iterator owns the temporary file. Each disk read or decode failure is returned as a crate::physical::ExecError, and dropping the iterator early still removes the temporary file.

Source

pub fn drain_all(&mut self) -> ExecResult<Vec<Batch>>

Drain and materialize every restored batch.

Source

pub fn drain_rows(&mut self) -> ExecResult<SpillRows<SpillDrain>>

Consume the buffer as a physical-row stream without collecting batches.

Source

pub fn clear(&mut self)

Discard all buffered data and remove any spill file.

Source

pub fn into_shared( self, schema: impl Into<RowSchema>, ) -> ExecResult<SharedSpill>

Seal this buffer as an immutable, cheaply cloneable materialization. Batches that fit within the configured byte budget remain in memory; once spilling has started, every pending batch is flushed and readers reopen the file independently. Both forms support repeatable scans without collecting the complete input again.

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> ErasedDestructor for T
where T: 'static,

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, 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.