Skip to main content

ExpressionEval

Struct ExpressionEval 

Source
pub struct ExpressionEval { /* private fields */ }
Expand description

Lightweight expression evaluator using direct VM execution.

ExpressionEval provides the simplest possible API for expression evaluation:

  1. Compile the expression once with new()
  2. Evaluate rows with eval() or eval_bool()

This is the recommended replacement for CompiledEvaluator when you have a single expression to evaluate repeatedly.

§Example

// Compile once
let eval = ExpressionEval::compile(&expr, &columns)?;

// Evaluate many rows
for row in rows {
    let value = eval.eval(&row)?;
    // or for boolean: let matches = eval.eval_bool(&row);
}

Implementations§

Source§

impl ExpressionEval

Source

pub fn compile(expr: &Expression, columns: &[String]) -> Result<Self>

Compile an expression for evaluation.

Source

pub fn compile_with_aliases( expr: &Expression, columns: &[String], aliases: &[(String, usize)], ) -> Result<Self>

Compile with expression aliases for HAVING clause evaluation.

Expression aliases map expression strings (like “SUM(amount)”) to column indices in the result row. This is used for HAVING clauses where aggregate expressions need to reference pre-computed aggregate results.

§Arguments
  • expr - The expression to compile
  • columns - Column names for the result row
  • aliases - Slice of (expression_name, column_index) pairs
§Example
// For HAVING SUM(amount) > 100, where SUM(amount) is at column 2
let aliases = vec![("sum(amount)".to_string(), 2)];
let eval = ExpressionEval::compile_with_aliases(&having_expr, &columns, &aliases)?;
Source

pub fn compile_with_options( expr: &Expression, columns: &[String], columns2: Option<&[String]>, outer_columns: Option<&[String]>, expression_aliases: Option<StringMap<u16>>, function_registry: &FunctionRegistry, ) -> Result<Self>

Compile with full context options.

Source

pub fn from_program(program: SharedProgram) -> Self

Create from a pre-compiled program.

Source

pub fn with_params(self, params: ParamVec) -> Self

Set query parameters.

Source

pub fn with_named_params(self, named_params: FxHashMap<String, Value>) -> Self

Set named parameters.

Source

pub fn with_context(self, ctx: &ExecutionContext) -> Self

Set context from ExecutionContext.

PERF: Both params and named_params share the Arc - zero cloning.

Source

pub fn with_transaction_id(self, txn_id: Option<u64>) -> Self

Set transaction ID.

Source

pub fn set_outer_row(&mut self, outer: &FxHashMap<CompactArc<str>, Value>)

Set outer row for correlated subqueries. Accepts CompactArc<str> keys directly to avoid conversion overhead.

Source

pub fn clear_outer_row(&mut self)

Clear outer row.

Source

pub fn eval(&mut self, row: &Row) -> Result<Value>

Evaluate the expression for a row.

Source

pub fn eval_bool(&mut self, row: &Row) -> Result<bool>

Evaluate as boolean (for WHERE/HAVING).

Source

pub fn eval_bool_checked(&mut self, row: &Row) -> Result<bool>

Like eval_bool but returns errors instead of swallowing them.

Source

pub fn eval_join(&mut self, left: &Row, right: &Row) -> Result<Value>

Evaluate with two rows (for joins).

Source

pub fn eval_join_bool(&mut self, left: &Row, right: &Row) -> Result<bool>

Evaluate join as boolean.

Source

pub fn eval_slice(&mut self, row: &Row) -> Result<Value>

Evaluate with a row reference.

Source

pub fn eval_slice_bool(&mut self, row: &Row) -> Result<bool>

Evaluate as boolean.

Source

pub fn program(&self) -> &SharedProgram

Get the underlying program.

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<T> CompactArcDrop for T

Source§

unsafe fn drop_and_dealloc(ptr: *mut u8)

Drop the contained data and deallocate the header+data allocation. Read more
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> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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