Skip to main content

RowFilter

Struct RowFilter 

Source
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

Source

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 filter
  • columns - Column names matching the row schema
Source

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 filter
  • columns - Column names matching the row schema
  • 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 filter = RowFilter::with_aliases(&having_expr, &columns, &aliases)?;

// Filter rows
for row in rows {
    if filter.matches(&row) {
        // row passes HAVING clause
    }
}
Source

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.

Source

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

Create a filter with query parameters.

Source

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

Create a filter with named parameters.

Source

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.

Source

pub fn from_program(program: SharedProgram) -> Self

Create a filter from a pre-compiled program.

Source

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.

Source

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.

Source

pub fn matches_deferred_checked(&self, row: &DeferredRow) -> Result<bool>

Evaluate a predicate over a compact JOIN row without materializing it.

Source

pub fn matches_row_ref_checked(&self, row: &RowRef) -> Result<bool>

Evaluate a predicate over a virtual executor row without materializing it.

Source

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

Source

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

Evaluate the filter expression and return the value.

Source

pub fn program(&self) -> &SharedProgram

Get the underlying program (for advanced use cases).

Trait Implementations§

Source§

impl Clone for RowFilter

Source§

fn clone(&self) -> RowFilter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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