pub struct MvRegistry { /* private fields */ }Expand description
Registry for managing materialized views.
Maintains a DAG of view dependencies and provides:
- Cycle detection on registration
- Topological ordering for correct processing order
- Dependency tracking for cascade operations
§Example
use laminar_core::mv::{MvRegistry, MaterializedView};
use arrow_schema::{Schema, Field, DataType};
use std::sync::Arc;
let mut registry = MvRegistry::new();
// Register base tables
registry.register_base_table("trades");
// Register cascading views
let schema = Arc::new(Schema::new(vec![Field::new("count", DataType::Int64, false)]));
let ohlc_1s = MaterializedView::new("ohlc_1s", "SELECT ...", vec!["trades".into()], schema.clone());
registry.register(ohlc_1s).unwrap();
let ohlc_1m = MaterializedView::new("ohlc_1m", "SELECT ...", vec!["ohlc_1s".into()], schema);
registry.register(ohlc_1m).unwrap();
// Views are processed in topological order
assert_eq!(registry.topo_order(), &["ohlc_1s", "ohlc_1m"]);Implementations§
Source§impl MvRegistry
impl MvRegistry
Sourcepub fn register_base_table(&mut self, name: impl Into<String>)
pub fn register_base_table(&mut self, name: impl Into<String>)
Registers a base table (source that is not an MV).
Base tables are assumed to exist and can be referenced as sources by materialized views.
Sourcepub fn is_base_table(&self, name: &str) -> bool
pub fn is_base_table(&self, name: &str) -> bool
Returns true if the given name is a registered base table.
Sourcepub fn register(&mut self, view: MaterializedView) -> Result<(), MvError>
pub fn register(&mut self, view: MaterializedView) -> Result<(), MvError>
Registers a new materialized view.
§Errors
Returns error if:
- View name already exists
- Source MV or base table doesn’t exist
- Would create a dependency cycle
Sourcepub fn unregister(&mut self, name: &str) -> Result<MaterializedView, MvError>
pub fn unregister(&mut self, name: &str) -> Result<MaterializedView, MvError>
Unregisters a materialized view.
§Errors
Returns error if:
- View doesn’t exist
- Other views depend on it (use
unregister_cascadeinstead)
Sourcepub fn unregister_cascade(
&mut self,
name: &str,
) -> Result<Vec<MaterializedView>, MvError>
pub fn unregister_cascade( &mut self, name: &str, ) -> Result<Vec<MaterializedView>, MvError>
Unregisters a materialized view and all views that depend on it.
Returns the views that were removed, in dependency order (dependents first).
§Errors
Returns error if the view doesn’t exist.
Sourcepub fn get(&self, name: &str) -> Option<&MaterializedView>
pub fn get(&self, name: &str) -> Option<&MaterializedView>
Gets a view by name.
Sourcepub fn get_mut(&mut self, name: &str) -> Option<&mut MaterializedView>
pub fn get_mut(&mut self, name: &str) -> Option<&mut MaterializedView>
Gets a mutable reference to a view by name.
Sourcepub fn topo_order(&self) -> &[String]
pub fn topo_order(&self) -> &[String]
Returns all views in topological order (dependencies first).
Sourcepub fn get_dependents(&self, source: &str) -> impl Iterator<Item = &str>
pub fn get_dependents(&self, source: &str) -> impl Iterator<Item = &str>
Returns all views that depend on the given source.
Sourcepub fn get_dependencies(&self, view: &str) -> impl Iterator<Item = &str>
pub fn get_dependencies(&self, view: &str) -> impl Iterator<Item = &str>
Returns all sources that the given view depends on.
Sourcepub fn views(&self) -> impl Iterator<Item = &MaterializedView>
pub fn views(&self) -> impl Iterator<Item = &MaterializedView>
Returns an iterator over all registered views.
Sourcepub fn base_tables(&self) -> &FxHashSet<String>
pub fn base_tables(&self) -> &FxHashSet<String>
Returns the set of registered base tables.
Sourcepub fn dependency_chain(&self, name: &str) -> Vec<String>
pub fn dependency_chain(&self, name: &str) -> Vec<String>
Returns the full dependency chain for a view (including transitive).
The chain is returned in topological order (dependencies first).
Trait Implementations§
Source§impl Debug for MvRegistry
impl Debug for MvRegistry
Source§impl Default for MvRegistry
impl Default for MvRegistry
Source§fn default() -> MvRegistry
fn default() -> MvRegistry
Auto Trait Implementations§
impl Freeze for MvRegistry
impl RefUnwindSafe for MvRegistry
impl Send for MvRegistry
impl Sync for MvRegistry
impl Unpin for MvRegistry
impl UnsafeUnpin for MvRegistry
impl UnwindSafe for MvRegistry
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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