Is it possible to send the compiled AST over the wire?

72 views
Skip to first unread message

Prathik Rajendran M

unread,
Apr 5, 2023, 11:26:28 PM4/5/23
to CEL Go Discussion Forum
Hello,

I am trying to optimize one of my CEL flows, one system takes in the CEL program and passes it to another system as a string. I was wondering if the system that builds the CEL script can parse and check the AST and then transfer the AST over the wire to the other service rather than have the other service parse and check again.

Example:
In system 1 user enters the CEL script, we then parse and check the script to ensure that it is correct and store it.

Then a request comes to system 1, it takes the CEL script and passes it over to system 2.

System 2 then compiles the CEL script (which is a string) to an AST and then builds a program from the AST and then evaluates the expression. This can happen multiple times because with each request system 1 sends the CEL script along with some other data to system 2.

Can we optimize by having to compile and check only once and system 1, and let system 2 only run the program?

Thank you

Tristan Swadell

unread,
Apr 5, 2023, 11:37:14 PM4/5/23
to Prathik Rajendran M, CEL Go Discussion Forum
Hi Prathik,

What you're describing is roughly what CEL was designed for. The ideal case is to parse / check in one process and evaluate in another. 

-Tristan

--
You received this message because you are subscribed to the Google Groups "CEL Go Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cel-go-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cel-go-discuss/c17e6ccf-7eeb-4c11-8935-127d28e2f673n%40googlegroups.com.

Prathik Rajendran M

unread,
Apr 6, 2023, 12:11:56 AM4/6/23
to Tristan Swadell, CEL Go Discussion Forum
Thanks Tristan, Is there any example of how I can send over the wire (preferable as a proto over gRPC)? I searched the cel-go codebase but was unable to figure it out. Would be great if you can give some pointers or code snippet of how to send it to another process.

Tristan Swadell

unread,
Apr 6, 2023, 12:25:11 AM4/6/23
to Prathik Rajendran M, CEL Go Discussion Forum
Hi Prathik,

You'll want to use `cel.AstToCheckedExpr()` to convert the AST to a protobuf, and then on the other side use `cel.CheckedExprToAst()`.

-Tristan
Reply all
Reply to author
Forward
0 new messages