Skip to main content

MongrelSession

Struct MongrelSession 

Source
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

Source

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.

Source

pub fn new_with_external_modules( db: Table, modules: impl IntoIterator<Item = Arc<dyn ExternalTableModule>>, ) -> Result<Self>

Source

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.

Source

pub fn open_with_external_modules( database: Arc<Database>, modules: impl IntoIterator<Item = Arc<dyn ExternalTableModule>>, ) -> Result<Self>

Source

pub fn register_external_module( &self, module: Arc<dyn ExternalTableModule>, ) -> Result<()>

Source

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.

Source

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).

Source

pub fn drop_view(&self, name: &str)

Drop a named materialized view.

Source

pub async fn register(&self, name: &str) -> Result<()>

Register the table under name so select * from <name> resolves.

Source

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.

Source

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.

Source

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.

Source

pub fn clear_cache(&self)

Drop all cached results (e.g. after a manual data change you want reflected immediately).

Source

pub fn context(&self) -> &SessionContext

Source

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.

Source

pub fn register_aggregate_udf(&self, f: AggregateUDF)

Register a custom aggregate SQL function on this session.

Source

pub fn register_window_udf(&self, f: WindowUDF)

Register a custom window SQL function on this session.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V