Skip to content

allow two-step compilation/evaluation #12

Description

@aschus

As far as I understand, this library is optimized for the use case of evaluating multiple CEL expressions against one and the same context. To also support efficiently evaluating the same CEL expression against multiple contexts, it would make sense to also expose the parsing/compilation step of cel-rust (i.e., the Program class). For example, something like:

filter = CelProgram(expression="person.age >= 18")
adults = [p for p in persons if filter.evaluate(context={"person": p})]

This would also allow exposing the references of the Program, which would be useful to e.g. optimize DB queries to only include the fields that are needed for evaluating some CEL filter expression.

assert CelProgram("age(person)").variable_references == ["person"]
assert CelProgram("age(person)").function_references == ["age"]

I am not sure, though, if this would play well with your type coercion add-on to cel-rust, but I could live with it being unavailable for that use case (see also #11).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions