pub struct ExpressionEval { /* private fields */ }Expand description
Lightweight expression evaluator using direct VM execution.
ExpressionEval provides the simplest possible API for expression evaluation:
- Compile the expression once with
new() - Evaluate rows with
eval()oreval_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
impl ExpressionEval
Sourcepub fn compile(expr: &Expression, columns: &[String]) -> Result<Self>
pub fn compile(expr: &Expression, columns: &[String]) -> Result<Self>
Compile an expression for evaluation.
Sourcepub fn compile_with_aliases(
expr: &Expression,
columns: &[String],
aliases: &[(String, usize)],
) -> Result<Self>
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 compilecolumns- Column names for the result rowaliases- 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)?;Sourcepub 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>
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.
Sourcepub fn from_program(program: SharedProgram) -> Self
pub fn from_program(program: SharedProgram) -> Self
Create from a pre-compiled program.
Sourcepub fn with_params(self, params: ParamVec) -> Self
pub fn with_params(self, params: ParamVec) -> Self
Set query parameters.
Sourcepub fn with_named_params(self, named_params: FxHashMap<String, Value>) -> Self
pub fn with_named_params(self, named_params: FxHashMap<String, Value>) -> Self
Set named parameters.
Sourcepub fn with_context(self, ctx: &ExecutionContext) -> Self
pub fn with_context(self, ctx: &ExecutionContext) -> Self
Set context from ExecutionContext.
PERF: Both params and named_params share the Arc - zero cloning.
Sourcepub fn with_transaction_id(self, txn_id: Option<u64>) -> Self
pub fn with_transaction_id(self, txn_id: Option<u64>) -> Self
Set transaction ID.
Sourcepub fn set_outer_row(&mut self, outer: &FxHashMap<CompactArc<str>, Value>)
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.
Sourcepub fn clear_outer_row(&mut self)
pub fn clear_outer_row(&mut self)
Clear outer row.
Sourcepub fn eval_bool_checked(&mut self, row: &Row) -> Result<bool>
pub fn eval_bool_checked(&mut self, row: &Row) -> Result<bool>
Like eval_bool but returns errors instead of swallowing them.
Sourcepub fn eval_join(&mut self, left: &Row, right: &Row) -> Result<Value>
pub fn eval_join(&mut self, left: &Row, right: &Row) -> Result<Value>
Evaluate with two rows (for joins).
Sourcepub fn eval_join_bool(&mut self, left: &Row, right: &Row) -> Result<bool>
pub fn eval_join_bool(&mut self, left: &Row, right: &Row) -> Result<bool>
Evaluate join as boolean.
Sourcepub fn eval_slice(&mut self, row: &Row) -> Result<Value>
pub fn eval_slice(&mut self, row: &Row) -> Result<Value>
Evaluate with a row reference.
Sourcepub fn eval_slice_bool(&mut self, row: &Row) -> Result<bool>
pub fn eval_slice_bool(&mut self, row: &Row) -> Result<bool>
Evaluate as boolean.
Sourcepub fn program(&self) -> &SharedProgram
pub fn program(&self) -> &SharedProgram
Get the underlying program.