CEL evaluation#
parcel_runtime::reference evaluates CEL expressions and converts caller, dataset, and Arrow values. Most applications can use the higher-level caller and validation functions.
Scope#
Field |
Type |
Meaning |
|---|---|---|
|
|
Caller namespace, when needed. |
|
|
Dataset namespace, when needed. |
|
|
Row namespace; absent keys represent null values. |
|
|
Exact custom function implementations the expression can call. |
Scope::default() has no namespace values and an empty pin set.
Context and evaluation#
pub fn context(scope: &Scope) -> cel::Context<'static>;
pub fn eval(src: &str, ctx: &cel::Context) -> Result<cel::Value, String>;
pub fn eval_bool(src: &str, ctx: &cel::Context) -> Result<bool, String>;
context registers the standard library, parcel functions, and the supplied namespaces. src is CEL expression text. Evaluation returns a value or an error string; eval_bool also rejects results that are not Boolean.
use parcel_runtime::{Caller, reference::{self, Scope}};
let caller = Caller::new("analyst", "globex", "purchasing");
let scope = Scope {
ctx: Some(reference::ctx_value(&caller)),
..Scope::default()
};
let context = reference::context(&scope);
assert_eq!(reference::eval_bool("ctx.tenant == 'globex'", &context), Ok(true));
Value conversion#
Signatures below use Value for cel::Value and Type for parcel_core::types::Type.
Signature |
Parameters and result |
|---|---|
|
Converts standard caller fields into a CEL namespace. |
|
Also converts declared custom caller fields according to their types. |
|
Converts JSON to the requested CEL type; returns |
|
Builds nested dataset values from dotted field paths and values. |
|
Creates a CEL string. |
|
Creates a CEL timestamp. |
|
Converts a CEL value to a typed DataFusion scalar, or returns an error. |
|
Converts a supported non-null scalar to CEL; otherwise returns |
|
Creates the Arrow list type for the element type. |
|
Returns the Arrow timestamp type used by the interpreter. |