Combining different CEL expressions into a single expression #593
-
| Apologies if I missed this in the documentation! I have a set of pre-compiled CEL expressions, and I'd like to combine them into a new expression via logical operators such as  | 
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
| @josephschorr We've shied away from merging pre-compiled expressions since this tends to be error prone. I would recommend using the  Your other alternative is to create aliases for the compiled expressions, e.g.  | 
Beta Was this translation helpful? Give feedback.
-
| Hi @TristonianJones, Thanks for the pointers! I ended up just keeping my own tree of expressions and operators, and executing each expression on its own, stitching the boolean results together as I go along | 
Beta Was this translation helpful? Give feedback.
@josephschorr We've shied away from merging pre-compiled expressions since this tends to be error prone. I would recommend using the
cel.AstToStringmethod to convert yourCheckedExprvalues to human-readable strings that you stitch together with&&,||, and!before recompiling the combined expression. The only drawback of this approach is that it requires you to have setup thecel.NewEnv()in a way that makes it possible to stitch these expressions together and compile them again.Your other alternative is to create aliases for the compiled expressions, e.g.
lazyExprs map[string]cel.Astand implement theinterpreter.Activationin a way that when the name of the lazy expression is provid…