Skip to main content

TermBatch

Struct TermBatch 

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

Columnar batch: each column is one bound variable.

A zero-column batch can still have rows: SPARQL’s empty group { } is one solution with no bindings (the join identity). Self::len is stored explicitly so that table is not confused with an empty (zero-row) result.

Implementations§

Source§

impl TermBatch

Source

pub fn try_new(columns: Vec<TermColumn>) -> Result<Self, ExecError>

Construct from columns; all must share the same length.

Source

pub fn empty(width: usize) -> Self

Empty batch with width zero-length columns (zero rows).

Source

pub fn with_capacity_rows(width: usize, rows: usize) -> Self

Empty batch with width columns, each reserving rows cells.

The exact-size constructor for a stack whose total height is known before its inputs are read: Self::concat grows its accumulator by doubling because an IntoIterator gives it no length, while a UNION’s collected arm list knows the sum, so every column can be allocated once at its final height and never reallocated.

A zero-width batch with a non-zero height exists only via Self::zero_width or a merge that kept one (Self::extend_aligned, Self::concat); this constructor starts at height 0 even when width == 0, because try_new of an empty column vec is defined as zero rows while a batch with no columns has nothing but its height to carry SPARQL’s empty group ({ } / ASK {}, one solution with no bindings).

Source

pub fn extend_aligned( &mut self, source: &Self, map: &[Option<usize>], ) -> Result<(), ExecError>

Append source’s rows under a column map.

map[out] = Some(i) fills output column out from source column i; None appends source.n_rows unbound cells. A zero-width source still adds its height, so a unit table (SPARQL’s empty group { }, one solution with no columns) survives a merge. The source is read in place — one extend_from_slice per output column — so a caller never materialises a re-ordered intermediate batch first. Pair it with Self::with_capacity_rows to make the whole stack one allocation and one copy per column.

map must carry one entry per output column and every Some index must name a source column; both are checked before anything is appended, so a rejected map leaves the batch untouched.

Source

pub fn push_unbound_columns(&mut self, count: usize)

Append count all-unbound columns, each self.n_rows cells tall.

For a merge whose schema grows after rows have already been stacked: a variable that only a later input binds is unbound for every row collected so far. The caller appends the new input’s rows afterwards with Self::extend_aligned, which fills the new columns from that input while leaving the zeros already written here in place.

Source

pub fn push_column(&mut self, column: TermColumn) -> Result<(), ExecError>

Append one column to the right edge. Its height must equal self.n_rows.

The O(1) schema extension used when an operator adds a column to a table it already holds (an Extend whose expression the executor evaluated once). The ids are taken as they are, so the caller interns.

Source

pub fn zero_width(n_rows: usize) -> Self

Zero columns and n_rows solutions (grounded scans, ASK-style pages).

Self::try_new of an empty column vec is always zero rows; a fully grounded pattern still has a row count.

Source

pub fn width(&self) -> usize

Number of columns.

Source

pub fn len(&self) -> usize

Number of rows.

For a zero-column batch this is the stored height, so a unit table (one empty mapping) reports 1 rather than 0.

Source

pub fn is_empty(&self) -> bool

Whether there are no rows.

Source

pub fn columns(&self) -> &[TermColumn]

Borrow columns.

Source

pub fn column(&self, index: usize) -> Result<&TermColumn, ExecError>

Borrow one column.

Source

pub fn any_bound(&self, index: usize) -> bool

Whether any row binds the column at index (false when the batch has no such column — an absent column binds nothing). One short-circuiting id scan, no dedupe and no promotion.

Source

pub fn from_rows( dict: &TermDict, width: usize, rows: Vec<Vec<EncodedTerm>>, ) -> Result<Self, ExecError>

Build from row-oriented bound terms (rows[r][c]), interned into dict.

Moves each cell into one Vec<EncodedTerm> per column, then TermColumn::from_terms (intern_column once per column). Unbound cells belong in Self::from_optional_rows.

Source

pub fn from_optional_rows( dict: &TermDict, width: usize, rows: Vec<Vec<Option<EncodedTerm>>>, ) -> Result<Self, ExecError>

Build from row-oriented optional terms (None = unbound).

Source

pub fn from_id_rows( width: usize, rows: Vec<Vec<u32>>, ) -> Result<Self, ExecError>

Build from already-interned id rows (rows[r][c] is a TermId).

Source

pub fn fill_optional_row( &self, dict: &TermDict, row: usize, out: &mut [Option<EncodedTerm>], )

Fill out with this row’s encoded terms (one dict lock).

out.len() must equal Self::width.

Source

pub fn to_optional_rows(&self, dict: &TermDict) -> Vec<Vec<Option<EncodedTerm>>>

Row-oriented view with resolved terms (None = unbound).

Packs every cell’s TermId then one TermDict::get_many for the frame (one mutex, not one lock per cell).

Source

pub fn to_rows(&self, dict: &TermDict) -> Vec<Vec<EncodedTerm>>

Row-oriented view; unbound cells panic — prefer Self::to_optional_rows when OPTIONAL is in play. Bound-only helper for tests and callers that never produce unbound mid-pipeline.

Source

pub fn concat( width: usize, batches: impl IntoIterator<Item = TermBatch>, ) -> Result<Self, ExecError>

Concatenate owned batches of one width into a single batch.

Every input must have exactly width columns — a mismatch is an error — and nothing is re-interned: ids are copied as they are. The first non-empty batch moves into the accumulator, so its column buffers are reused rather than copied; every later batch appends its ids.

A zero-width input contributes only its height, which is how SPARQL’s empty group ({ }, one solution with no bindings) survives a concatenation with a populated table.

This is the owning form and needs no length up front. Callers that hold borrowed sources and already know the total height want Self::with_capacity_rows plus Self::extend_aligned: one allocation at the final size and one copy per row.

Source

pub fn append(&mut self, other: &TermBatch) -> Result<(), ExecError>

Append other’s rows onto this batch (same width). Copies ids only.

Used by crate-external park accumulators that grow a RAM tail page-by-page. Empty other is a no-op. Zero-width batches add height without columns (SPARQL empty-mapping tables).

Source

pub fn clear_rows(&mut self)

Drop all rows; keep column width (empty Vec<u32> buffers).

Trait Implementations§

Source§

impl Clone for TermBatch

Source§

fn clone(&self) -> TermBatch

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 TermBatch

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TermBatch

Source§

fn eq(&self, other: &TermBatch) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TermBatch

Source§

impl StructuralPartialEq for TermBatch

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

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

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,