pub struct MongrelSession { /* private fields */ }Expand description
Convenience wrapper: a DataFusion SessionContext bound to a live MongrelDB,
with a result cache keyed by (sql, snapshot_epoch) that auto-invalidates
when a commit advances the epoch.
Implementations§
Source§impl MongrelSession
impl MongrelSession
Sourcepub fn new(db: Table) -> Self
pub fn new(db: Table) -> Self
Create a session over a live Table. Takes ownership; wrap in Arc if you
need to keep a handle for writes after registering the provider. Registers
the ann_search UDF so SQL semantic-search predicates parse.
pub fn new_with_external_modules( db: Table, modules: impl IntoIterator<Item = Arc<dyn ExternalTableModule>>, ) -> Result<Self>
Sourcepub fn open(database: Arc<Database>) -> Result<Self>
pub fn open(database: Arc<Database>) -> Result<Self>
Open a session over a multi-table Database (spec §12). Auto-registers
every live table as a MongrelProvider; the cache epoch is driven by
Database::visible_epoch() so any table’s commit invalidates cached
results.
pub fn open_with_external_modules( database: Arc<Database>, modules: impl IntoIterator<Item = Arc<dyn ExternalTableModule>>, ) -> Result<Self>
pub fn register_external_module( &self, module: Arc<dyn ExternalTableModule>, ) -> Result<()>
Sourcepub fn db(&self) -> Option<&Arc<Mutex<Table>>>
pub fn db(&self) -> Option<&Arc<Mutex<Table>>>
The underlying Table handle (Phase 19.3: used by the daemon for direct
put/delete/commit/count access). Returns None when the session was
opened over an empty Database.
Sourcepub fn create_view(&self, name: &str, sql: &str)
pub fn create_view(&self, name: &str, sql: &str)
Phase 17.3: create a named materialized view backed by a SQL query.
SELECT * FROM <name> resolves to the view’s defining SQL, which is
executed (or served from the result cache) transparently. The view is
automatically invalidated on commit (via the epoch-keyed result cache).
Sourcepub async fn register(&self, name: &str) -> Result<()>
pub async fn register(&self, name: &str) -> Result<()>
Register the table under name so select * from <name> resolves.
Sourcepub async fn register_db(&self, name: &str, db: Table) -> Result<()>
pub async fn register_db(&self, name: &str, db: Table) -> Result<()>
Register a second (or further) live Table as another table on the same
session, enabling cross-table SQL joins. The first Table (passed to
Self::new) still owns the result-cache epoch: cached results are
invalidated on its commits, so mutate the primary table last or call
Self::clear_cache after writing a secondary table.
Sourcepub async fn run(&self, sql: &str) -> Result<Vec<RecordBatch>>
pub async fn run(&self, sql: &str) -> Result<Vec<RecordBatch>>
Run a SQL statement: DDL/commands are intercepted; otherwise a result
cache keyed by (normalized SQL, snapshot epoch) memoizes batches.
§5.3: simple single-table SELECTs are served by [try_direct_dispatch]
(no DataFusion planning) before falling back to the full DataFusion path.
Sourcepub async fn run_sql_traced(
&self,
sql: &str,
) -> Result<(Vec<RecordBatch>, QueryTrace)>
pub async fn run_sql_traced( &self, sql: &str, ) -> Result<(Vec<RecordBatch>, QueryTrace)>
Self::run with a captured mongreldb_core::trace::QueryTrace.
Runs the SQL query inside a trace-capture scope so that path-decision
recordings from both the SQL scan layer (MongrelProvider::scan) and
the core engine (Table::native_page_cursor, query_columns_native,
count_conditions, etc.) are collected into a single returned trace.
The session-level result cache returns before scan() runs on a hit, so
a session-cache hit yields scan_mode = Unknown. For scan-level
result-cache tracing, use
mongreldb_core::Table::query_columns_native_cached_traced.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Drop all cached results (e.g. after a manual data change you want reflected immediately).
pub fn context(&self) -> &SessionContext
Sourcepub fn register_scalar_udf(&self, f: ScalarUDF)
pub fn register_scalar_udf(&self, f: ScalarUDF)
Register a custom scalar SQL function on this session.
This is the Rust escape hatch for application-defined SQL functions. The session’s plan and result caches are cleared because function resolution can change query output without advancing the storage epoch.
Sourcepub fn register_aggregate_udf(&self, f: AggregateUDF)
pub fn register_aggregate_udf(&self, f: AggregateUDF)
Register a custom aggregate SQL function on this session.
Sourcepub fn register_window_udf(&self, f: WindowUDF)
pub fn register_window_udf(&self, f: WindowUDF)
Register a custom window SQL function on this session.
Auto Trait Implementations§
impl !Freeze for MongrelSession
impl !RefUnwindSafe for MongrelSession
impl !UnwindSafe for MongrelSession
impl Send for MongrelSession
impl Sync for MongrelSession
impl Unpin for MongrelSession
impl UnsafeUnpin for MongrelSession
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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