pub struct ExecutionState<'a> { /* private fields */ }Expand description
A handle on a database that may be in the process of running a rule.
An ExecutionState grants immutable access to the (much of) the database, and also provides a limited API to mutate database contents.
A few important notes:
§Some tables may be missing
Callers external to this crate cannot construct an ExecutionState directly. Depending on the
context, some tables may not be available. In particular, when running crate::Table::merge
operations, only a table’s read-side dependencies are available for reading (sim. for writing).
This allows tables that do not need access to one another to be merged in parallel.
When executing a rule, ExecutionState has access to all tables.
§Limited Mutability
Callers can only stage insertsions and deletions to tables. These changes are not applied until
the next call to merge on the underlying table.
§Predicted Values
ExecutionStates provide a means of synchronizing the results of a pending write across
different executions of a rule. This is particularly important in the case where the result of
an operation (such as “lookup or insert new id” operatiosn) is a fresh id. A common
ExecutionState ensures that future lookups will see the same id (even across calls to
ExecutionState::clone).
Implementations§
Source§impl<'a> ExecutionState<'a>
impl<'a> ExecutionState<'a>
Sourcepub fn stage_insert(&mut self, table: TableId, row: &[Value])
pub fn stage_insert(&mut self, table: TableId, row: &[Value])
Stage an insertion of the given row into table.
If you are using egglog, consider using egglog_bridge::TableAction.
Sourcepub fn stage_remove(&mut self, table: TableId, key: &[Value])
pub fn stage_remove(&mut self, table: TableId, key: &[Value])
Stage a removal of the given row from table if it is present.
If you are using egglog, consider using egglog_bridge::TableAction.
Sourcepub fn call_external_func(
&mut self,
func: ExternalFunctionId,
args: &[Value],
) -> Option<Value>
pub fn call_external_func( &mut self, func: ExternalFunctionId, args: &[Value], ) -> Option<Value>
Call an external function.
pub fn inc_counter(&self, ctr: CounterId) -> usize
pub fn read_counter(&self, ctr: CounterId) -> usize
Sourcepub fn get_table(&self, table: TableId) -> &'a WrappedTable
pub fn get_table(&self, table: TableId) -> &'a WrappedTable
Get an immutable reference to the table with id table.
Dangerous: Reading from a table during action execution may break the semi-naive evaluation
pub fn base_values(&self) -> &BaseValues
pub fn container_values(&self) -> &'a ContainerValues
Sourcepub fn predict_val(
&mut self,
table: TableId,
key: &[Value],
vals: impl ExactSizeIterator<Item = MergeVal>,
) -> Pooled<Vec<Value>>
pub fn predict_val( &mut self, table: TableId, key: &[Value], vals: impl ExactSizeIterator<Item = MergeVal>, ) -> Pooled<Vec<Value>>
Get the current value for a given key in table, or otherwise insert
the unique next value.
Insertions into tables are not performed immediately, but rules and merge functions sometimes need to get the result of an insertion. For such cases, executions keep a cache of “predicted” values for a given mapping that manage the insertions, etc.
If you are using egglog, consider using egglog_bridge::TableAction.
Sourcepub fn predict_col(
&mut self,
table: TableId,
key: &[Value],
vals: impl ExactSizeIterator<Item = MergeVal>,
col: ColumnId,
) -> Value
pub fn predict_col( &mut self, table: TableId, key: &[Value], vals: impl ExactSizeIterator<Item = MergeVal>, col: ColumnId, ) -> Value
A variant of ExecutionState::predict_val that avoids materializing the full row, and
instead only returns the value in the given column.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ExecutionState<'a>
impl<'a> !RefUnwindSafe for ExecutionState<'a>
impl<'a> Send for ExecutionState<'a>
impl<'a> Sync for ExecutionState<'a>
impl<'a> Unpin for ExecutionState<'a>
impl<'a> !UnwindSafe for ExecutionState<'a>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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