pub struct RowFilter { /* private fields */ }Expand description
A lightweight, thread-safe row filter for closure-based filtering.
RowFilter pre-compiles the expression once and can be cloned cheaply
(it uses CompactArc<Program> internally). Each thread should create its own
ExprVM for execution.
§Example
// Create filter once
let filter = RowFilter::new(&where_expr, &columns)?;
// Use in closure (filter is cloned into closure)
let predicate = move |row: &Row| filter.matches(row);
// Or use with parallel iteration
rows.par_iter().filter(|row| filter.matches(row)).collect()Implementations§
Source§impl RowFilter
impl RowFilter
Sourcepub fn new(expr: &Expression, columns: &[String]) -> Result<Self>
pub fn new(expr: &Expression, columns: &[String]) -> Result<Self>
Create a new row filter by compiling the given expression.
§Arguments
expr- The boolean expression to use as filtercolumns- Column names matching the row schema
Sourcepub fn with_aliases(
expr: &Expression,
columns: &[String],
aliases: &[(String, usize)],
) -> Result<Self>
pub fn with_aliases( expr: &Expression, columns: &[String], aliases: &[(String, usize)], ) -> Result<Self>
Create a row filter 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 boolean expression to use as filtercolumns- Column names matching the row schemaaliases- 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 filter = RowFilter::with_aliases(&having_expr, &columns, &aliases)?;
// Filter rows
for row in rows {
if filter.matches(&row) {
// row passes HAVING clause
}
}Sourcepub fn with_aliases_and_context(
expr: &Expression,
columns: &[String],
aliases: &[(String, usize)],
execution: &ExecutionContext,
) -> Result<Self>
pub fn with_aliases_and_context( expr: &Expression, columns: &[String], aliases: &[(String, usize)], execution: &ExecutionContext, ) -> Result<Self>
Compile a HAVING/filter expression with aliases and lexical outer scope
bound at the same time. Compiling first and attaching only parameters
later cannot emit LoadOuterColumn instructions.
Sourcepub fn with_params(self, params: ParamVec) -> Self
pub fn with_params(self, params: ParamVec) -> Self
Create a filter with 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
Create a filter with named parameters.
Sourcepub fn with_context(self, ctx: &ExecutionContext) -> Self
pub fn with_context(self, ctx: &ExecutionContext) -> Self
Create a filter from execution context.
PERF: Both params and named_params share the Arc - zero cloning.
Sourcepub fn from_program(program: SharedProgram) -> Self
pub fn from_program(program: SharedProgram) -> Self
Create a filter from a pre-compiled program.
Sourcepub fn matches(&self, row: &Row) -> Result<bool>
pub fn matches(&self, row: &Row) -> Result<bool>
Check if a row matches the filter condition.
This method is thread-safe and can be called from multiple threads. Each call uses a thread-local VM for execution.
Sourcepub fn matches_checked(&self, row: &Row) -> Result<bool>
pub fn matches_checked(&self, row: &Row) -> Result<bool>
Explicit checked alias retained for callers that spell out fallibility.
matches() and this method both propagate runtime and result-type errors.
Sourcepub fn matches_deferred_checked(&self, row: &DeferredRow) -> Result<bool>
pub fn matches_deferred_checked(&self, row: &DeferredRow) -> Result<bool>
Evaluate a predicate over a compact JOIN row without materializing it.
Sourcepub fn matches_row_ref_checked(&self, row: &RowRef) -> Result<bool>
pub fn matches_row_ref_checked(&self, row: &RowRef) -> Result<bool>
Evaluate a predicate over a virtual executor row without materializing it.
Sourcepub fn retain_checked(&self, rows: &mut RowVec) -> Result<()>
pub fn retain_checked(&self, rows: &mut RowVec) -> Result<()>
Filter a RowVec in-place, removing rows that don’t match. Returns Err if the filter expression produces a runtime error (e.g. invalid REGEXP pattern supplied via a parameter).
Sourcepub fn evaluate(&self, row: &Row) -> Result<Value>
pub fn evaluate(&self, row: &Row) -> Result<Value>
Evaluate the filter expression and return the value.
Sourcepub fn program(&self) -> &SharedProgram
pub fn program(&self) -> &SharedProgram
Get the underlying program (for advanced use cases).