Skip to main content

Module expression

Module expression 

Source
Available on crate feature expression only.
Expand description

CEL expression evaluation – compile, evaluate, validate.

Provides a DFE-profile-restricted CEL expression evaluator built on the cel crate (renamed from cel-interpreter). Both Python (via common-expression-language PyO3 bindings) and Rust use the same underlying Rust crate, ensuring identical parsing and evaluation semantics across all DFE components.

§DFE Expression Profile

Only a high-performance subset of CEL is allowed:

CategoryExamples
Comparison==, !=, <, <=, >, >=
Logical&&, ||, !
Membershipin
Stringcontains(), startsWith(), endsWith()
Existencehas()
Sizesize()
Ternary? :
Type castsint(), double(), string(), bool()
Arithmetic+, -, *, /, %

Restricted (blocked by default, opt-in via ProfileConfig):

  • Regex: matches() – unbounded cost per record
  • Iteration: map(), filter(), exists(), all() – O(n) per collection
  • Time: timestamp(), duration() – ClickHouse handles natively

§Usage

use hyperi_rustlib::expression::{compile, evaluate, evaluate_condition, validate};
use std::collections::HashMap;
use serde_json::json;

// Validate (returns errors list, empty if valid)
assert!(validate(r#"severity == "critical""#).is_empty());

// One-shot evaluation
let mut data = HashMap::new();
data.insert("amount".into(), json!(15000));
let result = evaluate("amount > 10000", &data).unwrap();
assert_eq!(result, true.into());

// Boolean condition (missing fields → false)
assert!(!evaluate_condition(r#"severity == "critical""#, &HashMap::new()));

// Compile for hot-path reuse
let program = compile("score > threshold").unwrap();
// ... program.execute(&context) per record

See dfe-engine/docs/EXPRESSIONS-CEL.md for the full profile specification.

Re-exports§

pub use error::ExpressionError;
pub use error::ExpressionResult;
pub use evaluator::build_context;
pub use evaluator::compile;
pub use evaluator::compile_with_config;
pub use evaluator::evaluate;
pub use evaluator::evaluate_condition;
pub use evaluator::validate;
pub use evaluator::validate_with_config;
pub use profile::ALLOWED_FUNCTIONS;
pub use profile::DISALLOWED_FUNCTIONS;
pub use profile::ProfileConfig;
pub use profile::RESTRICTED_ITERATION;
pub use profile::RESTRICTED_REGEX;
pub use profile::RESTRICTED_TIME;
pub use profile::check_profile_with_config;

Modules§

error
Error types for CEL expression compilation and evaluation.
evaluator
Core CEL expression operations – compile, evaluate, validate.
profile
DFE expression profile – allowed and restricted CEL functions.