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
impl TermBatch
Sourcepub fn try_new(columns: Vec<TermColumn>) -> Result<Self, ExecError>
pub fn try_new(columns: Vec<TermColumn>) -> Result<Self, ExecError>
Construct from columns; all must share the same length.
Sourcepub fn with_capacity_rows(width: usize, rows: usize) -> Self
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).
Sourcepub fn extend_aligned(
&mut self,
source: &Self,
map: &[Option<usize>],
) -> Result<(), ExecError>
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.
Sourcepub fn push_unbound_columns(&mut self, count: usize)
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.
Sourcepub fn push_column(&mut self, column: TermColumn) -> Result<(), ExecError>
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.
Sourcepub fn zero_width(n_rows: usize) -> Self
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.
Sourcepub fn len(&self) -> usize
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.
Sourcepub fn columns(&self) -> &[TermColumn]
pub fn columns(&self) -> &[TermColumn]
Borrow columns.
Sourcepub fn any_bound(&self, index: usize) -> bool
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.
Sourcepub fn from_rows(
dict: &TermDict,
width: usize,
rows: Vec<Vec<EncodedTerm>>,
) -> Result<Self, ExecError>
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.
Sourcepub fn from_optional_rows(
dict: &TermDict,
width: usize,
rows: Vec<Vec<Option<EncodedTerm>>>,
) -> Result<Self, ExecError>
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).
Sourcepub fn from_id_rows(
width: usize,
rows: Vec<Vec<u32>>,
) -> Result<Self, ExecError>
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).
Sourcepub fn fill_optional_row(
&self,
dict: &TermDict,
row: usize,
out: &mut [Option<EncodedTerm>],
)
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.
Sourcepub fn to_optional_rows(&self, dict: &TermDict) -> Vec<Vec<Option<EncodedTerm>>>
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).
Sourcepub fn to_rows(&self, dict: &TermDict) -> Vec<Vec<EncodedTerm>>
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.
Sourcepub fn concat(
width: usize,
batches: impl IntoIterator<Item = TermBatch>,
) -> Result<Self, ExecError>
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.
Sourcepub fn append(&mut self, other: &TermBatch) -> Result<(), ExecError>
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).
Sourcepub fn clear_rows(&mut self)
pub fn clear_rows(&mut self)
Drop all rows; keep column width (empty Vec<u32> buffers).