Skip to main content

Crate zerodds_sql_filter

Crate zerodds_sql_filter 

Source
Expand description

OMG DDS content-filter-expression parser + evaluator.

Safety classification: SAFE (a pure parser + evaluator, no data flows from external networks without caller mediation).

Spec: OMG DDS 1.4 §B.2.1 “Filter expressions”. The syntax is a SQL-92 subset, extended with %N parameter placeholders.

§Current scope

  • Literals: string ('...'), integer (i64), float (f64), boolean (TRUE/FALSE).
  • Identifiers: dotted (a.b.c) — for nested field access.
  • Parameter placeholders: %0, %1, …
  • Comparison ops: =, !=, <>, <, <=, >, >=, LIKE.
  • Boolean ops: AND, OR, NOT.
  • Parentheses.
  • LIKE wildcards: % (several characters), _ (one character).

Not in the MVP: BETWEEN ... AND, IN (...), IS NULL. Those follow in 3.7c.

§Architecture

  1. lexer: tokenizer. All keywords case-insensitive, string literals '...' with '' escape.
  2. parser: recursive descent with precedence climbing — OR < AND < NOT < comparison < atom.
  3. ast: data types for expressions + Value.
  4. evaluator: Expr::evaluate(row, params)bool; row implements RowAccess (field lookup by name).

§Usage

use zerodds_sql_filter::{parse, Value, RowAccess};
use std::collections::HashMap;

struct MapRow(HashMap<String, Value>);
impl RowAccess for MapRow {
    fn get(&self, path: &str) -> Option<Value> {
        self.0.get(path).cloned()
    }
}

let expr = parse("color = %0 AND x > 10").expect("parse");
let row = MapRow(HashMap::from([
    ("color".into(), Value::String("RED".into())),
    ("x".into(),     Value::Int(42)),
]));
let params = [Value::String("RED".into())];
assert_eq!(expr.evaluate(&row, &params), Ok(true));

Structs§

ParseError
Parse error with a human-readable message.

Enums§

EvalError
Error during evaluation.
Expr
A filter expression. A recursive tree, produced by crate::parse.
Value
An evaluable scalar value. OMG allows more types (char, etc.) — we deliberately map narrowly to the most common cases here.

Traits§

RowAccess
Row abstraction: access to the fields of a sample.

Functions§

parse
Parse entry point. The entire input must be part of exactly one expression — leftover strings are treated as errors.