pub struct IncrementalViewMaintainer { /* private fields */ }Expand description
Manages a collection of MaterializedViews and propagates delta changes.
§Workflow
- Call
register_viewto create a new view from aViewDefinitionand an initial result set. - Call
apply_delta(orqueue_change+flush_changes) whenever the underlying triple store changes. - Invalidated views can be re-evaluated by the caller and refreshed with new rows via internal access to the views map (or by replacing the whole view).
Implementations§
Source§impl IncrementalViewMaintainer
impl IncrementalViewMaintainer
Sourcepub fn register_view(&mut self, def: ViewDefinition, initial_rows: Vec<ViewRow>)
pub fn register_view(&mut self, def: ViewDefinition, initial_rows: Vec<ViewRow>)
Register a named view.
If a view with the same definition.name already exists it is
replaced.
Sourcepub fn apply_delta(&mut self, change: DeltaChange) -> Vec<String>
pub fn apply_delta(&mut self, change: DeltaChange) -> Vec<String>
Apply a single DeltaChange immediately.
Returns the names of views that were invalidated (i.e. whose
dependencies include the changed predicate or are empty).
Views that are already stale are not returned again (no-duplicate
semantics).
Sourcepub fn invalidate_view(&mut self, name: &str)
pub fn invalidate_view(&mut self, name: &str)
Mark a view as stale by name.
Does nothing if the view does not exist.
Sourcepub fn get_view(&self, name: &str) -> Option<&MaterializedView>
pub fn get_view(&self, name: &str) -> Option<&MaterializedView>
Return an immutable reference to a view.
Sourcepub fn list_views(&self) -> Vec<&str>
pub fn list_views(&self) -> Vec<&str>
Return the names of all registered views, in unspecified order.
Sourcepub fn affected_views(&self, predicate: &str) -> Vec<&str>
pub fn affected_views(&self, predicate: &str) -> Vec<&str>
Return the names of all views that depend on predicate.
This includes views with an empty dependencies list (universal
dependency).
Sourcepub fn queue_change(&mut self, change: DeltaChange)
pub fn queue_change(&mut self, change: DeltaChange)
Push a change onto the internal queue for later batch processing.
Sourcepub fn flush_changes(&mut self) -> HashMap<String, usize>
pub fn flush_changes(&mut self) -> HashMap<String, usize>
Apply all queued changes at once and clear the queue.
Returns a map of view_name → rows_changed. Because this
implementation uses a mark-stale strategy, invalidated views are
reported with 0 changed rows. Views that were not affected are not
included in the returned map.
Sourcepub fn view_count(&self) -> usize
pub fn view_count(&self) -> usize
Return the number of registered views.
Sourcepub fn total_rows(&self) -> usize
pub fn total_rows(&self) -> usize
Return the total number of cached rows across all non-stale views.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for IncrementalViewMaintainer
impl RefUnwindSafe for IncrementalViewMaintainer
impl Send for IncrementalViewMaintainer
impl Sync for IncrementalViewMaintainer
impl Unpin for IncrementalViewMaintainer
impl UnsafeUnpin for IncrementalViewMaintainer
impl UnwindSafe for IncrementalViewMaintainer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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