Skip to main content

Batch

Trait Batch 

Source
pub trait Batch:
    BatchReader
    + Clone
    + Send
    + Sync
where Self: Sized,
{ type Timed<T: Timestamp>: Batch<Key = <Self as BatchReader>::Key, Val = <Self as BatchReader>::Val, Time = T, R = <Self as BatchReader>::R>; type Batcher: Batcher<Self>; type Builder: Builder<Self>; // Required methods fn key_bounds(&self) -> Option<(&Self::Key, &Self::Key)>; fn touched_window_count(&self) -> TouchedWindowCount; fn negative_weight_count(&self) -> Option<u64>; // Provided methods fn dyn_from_tuples( factories: &Self::Factories, time: Self::Time, tuples: &mut Box<DynWeightedPairs<DynPair<Self::Key, Self::Val>, Self::R>>, ) -> Self { ... } fn from_batch<BI>( batch: &BI, timestamp: &Self::Time, factories: &Self::Factories, ) -> Self where BI: BatchReader<Key = Self::Key, Val = Self::Val, Time = (), R = Self::R> { ... } fn from_arc_batch<BI>( batch: &Arc<BI>, timestamp: &Self::Time, factories: &Self::Factories, ) -> Arc<Self> where BI: BatchReader<Key = Self::Key, Val = Self::Val, Time = (), R = Self::R> { ... } fn from_cursor<C>( cursor: C, timestamp: &Self::Time, factories: &Self::Factories, key_capacity: usize, value_capacity: usize, ) -> Self where C: Cursor<Self::Key, Self::Val, (), Self::R> { ... } fn dyn_empty(factories: &Self::Factories) -> Self { ... } fn filter(&self, predicate: &dyn Fn(&Self::Key, &Self::Val) -> bool) -> Self where Self::Time: PartialEq<()> + From<()> { ... } fn persisted(&self) -> Option<Self> { ... } fn file_reader(&self) -> Option<Arc<dyn FileReader>> { ... } fn from_path( _factories: &Self::Factories, _path: &StoragePath, ) -> Result<Self, ReaderError> { ... } }
Expand description

A BatchReader plus features for constructing new batches.

Batch extends BatchReader with types for constructing new batches from ordered tuples (Self::Builder) or unordered tuples (Self::Batcher), or by merging traces of like types, plus some convenient methods for using those types.

See crate documentation for more information on batches and traces.

Required Associated Types§

Source

type Timed<T: Timestamp>: Batch<Key = <Self as BatchReader>::Key, Val = <Self as BatchReader>::Val, Time = T, R = <Self as BatchReader>::R>

A batch type equivalent to Self, but with timestamp type T instead of Self::Time.

Source

type Batcher: Batcher<Self>

A type used to assemble batches from disordered updates.

Source

type Builder: Builder<Self>

A type used to assemble batches from ordered update sequences.

Required Methods§

Source

fn key_bounds(&self) -> Option<(&Self::Key, &Self::Key)>

Minimum and maximum keys in this batch.

File-backed batches materialize these bounds at write time. In-memory batches compute them from their ordered key storage. Merge builders use these bounds to decide whether a batch span can be encoded into a roaring bitmap.

Returns None for empty batches.

Source

fn touched_window_count(&self) -> TouchedWindowCount

Exact number of 16-bit roaring windows touched by the batch, relative to the batch minimum.

File-backed batches materialize this count at write time. In-memory batches track it while they are built. The merge-time filter predictor uses it together with min/max span overlap to estimate how many roaring containers the merged batch will likely touch.

A value of 0 means the batch cannot provide an exact count, e.g. the key type is not roaring-compatible, the batch span does not fit in u32, or the batch is empty.

Source

fn negative_weight_count(&self) -> Option<u64>

The number of tuples with negative weights in the batch.

This metric is used in merger heuristics. Negative weights are likely to cancel out with positive weights when merging the batch with other batches in the spine; therefore the merger will merge such batches more aggressively than it otherwise would based on the batch size only.

This heuristic is not useful for all batch types, in particular negative weights in batches produced by recursive queries do not generally cancel out. For such batches we don’t track negative weights, and this method returns None.

Provided Methods§

Source

fn dyn_from_tuples( factories: &Self::Factories, time: Self::Time, tuples: &mut Box<DynWeightedPairs<DynPair<Self::Key, Self::Val>, Self::R>>, ) -> Self

Assemble an unordered vector of weighted items into a batch.

Source

fn from_batch<BI>( batch: &BI, timestamp: &Self::Time, factories: &Self::Factories, ) -> Self
where BI: BatchReader<Key = Self::Key, Val = Self::Val, Time = (), R = Self::R>,

Creates a new batch as a copy of batch, using timestamp for all of the new batch’s timestamps This is useful for adding a timestamp to a batch, or for converting between different batch implementations (e.g. writing an in-memory batch to disk).

TODO: for adding a timestamp to a batch, this could be implemented more efficiently by having a special batch type where all updates have the same timestamp, as this is the only kind of batch that we ever create directly in DBSP; batches with multiple timestamps are only created as a result of merging. The main complication is that we will need to extend the trace implementation to work with batches of multiple types. This shouldn’t be too hard and is on the todo list.

Source

fn from_arc_batch<BI>( batch: &Arc<BI>, timestamp: &Self::Time, factories: &Self::Factories, ) -> Arc<Self>
where BI: BatchReader<Key = Self::Key, Val = Self::Val, Time = (), R = Self::R>,

Like from_batch, but avoids cloning the batch if the output type is identical to the input type.

Source

fn from_cursor<C>( cursor: C, timestamp: &Self::Time, factories: &Self::Factories, key_capacity: usize, value_capacity: usize, ) -> Self
where C: Cursor<Self::Key, Self::Val, (), Self::R>,

Creates a new batch as a copy of the tuples accessible via cursor``, using timestamp` for all of the new batch’s timestamps.

Source

fn dyn_empty(factories: &Self::Factories) -> Self

Creates an empty batch.

Source

fn filter(&self, predicate: &dyn Fn(&Self::Key, &Self::Val) -> bool) -> Self
where Self::Time: PartialEq<()> + From<()>,

Returns elements from self that satisfy a predicate.

Source

fn persisted(&self) -> Option<Self>

If this batch is not on storage, but supports writing itself to storage, this method writes it to storage and returns the stored version.

Source

fn file_reader(&self) -> Option<Arc<dyn FileReader>>

This functions returns the file that can be used to restore the batch’s contents.

If the batch can not be persisted, this function returns None.

Source

fn from_path( _factories: &Self::Factories, _path: &StoragePath, ) -> Result<Self, ReaderError>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<K, R> Batch for FallbackWSet<K, R>
where K: DataTrait + ?Sized, R: WeightTrait + ?Sized,

Source§

impl<K, R> Batch for FileWSet<K, R>
where K: DataTrait + ?Sized, R: WeightTrait + ?Sized,

Source§

impl<K, T, R, O> Batch for VecKeyBatch<K, T, R, O>
where K: DataTrait + ?Sized, T: Timestamp, R: WeightTrait + ?Sized, O: OrdOffset,

Source§

type Timed<T2: Timestamp> = VecKeyBatch<K, T2, R, O>

Source§

type Batcher = MergeBatcher<VecKeyBatch<K, T, R, O>>

Source§

type Builder = VecKeyBuilder<K, T, R, O>

Source§

impl<K, T, R> Batch for FallbackKeyBatch<K, T, R>
where K: DataTrait + ?Sized, T: Timestamp, R: WeightTrait + ?Sized,

Source§

impl<K, T, R> Batch for FileKeyBatch<K, T, R>
where K: DataTrait + ?Sized, T: Timestamp, R: WeightTrait + ?Sized,

Source§

impl<K, V, R, O> Batch for VecIndexedWSet<K, V, R, O>
where K: DataTrait + ?Sized, V: DataTrait + ?Sized, R: WeightTrait + ?Sized, O: OrdOffset,

Source§

impl<K, V, R> Batch for FallbackIndexedWSet<K, V, R>
where K: DataTrait + ?Sized, V: DataTrait + ?Sized, R: WeightTrait + ?Sized,

Source§

impl<K, V, R> Batch for FileIndexedWSet<K, V, R>
where K: DataTrait + ?Sized, V: DataTrait + ?Sized, R: WeightTrait + ?Sized,

Source§

impl<K, V, T, R, O> Batch for VecValBatch<K, V, T, R, O>
where K: DataTrait + ?Sized, V: DataTrait + ?Sized, R: WeightTrait + ?Sized, T: Timestamp, O: OrdOffset,

Source§

type Timed<T2: Timestamp> = VecValBatch<K, V, T2, R, O>

Source§

type Batcher = MergeBatcher<VecValBatch<K, V, T, R, O>>

Source§

type Builder = VecValBuilder<K, V, T, R, O>

Source§

impl<K, V, T, R> Batch for FallbackValBatch<K, V, T, R>
where K: DataTrait + ?Sized, V: DataTrait + ?Sized, T: Timestamp, R: WeightTrait + ?Sized,

Source§

impl<K, V, T, R> Batch for FileValBatch<K, V, T, R>
where K: DataTrait + ?Sized, V: DataTrait + ?Sized, T: Timestamp, R: WeightTrait + ?Sized,

Source§

type Timed<T2: Timestamp> = FileValBatch<K, V, T2, R>

Source§

type Batcher = MergeBatcher<FileValBatch<K, V, T, R>>

Source§

type Builder = FileValBuilder<K, V, T, R>

Source§

impl<K: DataTrait + ?Sized, R: WeightTrait + ?Sized> Batch for VecWSet<K, R>