I am aware that you can create global expressions with Esper's Statement Object Model using CreateExpressionClause
and ExpressionDeclaration
, but I'm not exactly sure how you are able to refer to their aliases when building an EPStatementObjectModel
for a pattern. For example, say I have a pattern like this:
every (a=Event(fizz = 3 and buzz = 5) -> b=Event(fizz = 3 and buzz = 5 and foo = 1 and bar = 2))
I would like to declare fizz = 3 and buzz = 5
as a global expression as such:
create expression fizzbuzz alias for {fizz = 3 and buzz = 5}
Therefore, with EPL I could successfully simplify the pattern to the following:
every (a=Event(fizzbuzz) -> b=Event(fizzbuzz and foo = 1 and bar = 2))
I cannot seem to find a method in any of the classes in com.espertech.esper.client.soda
in which I can refer to the global expression alias as I build the statement object. The best thing I could think of that would give me a valid pattern when converting the statement object to EPL would involve Expressions.property(alias)
, but I get the following error when I add the complete statement object to the Esper engine:
Failed to validate filter expression 'fizzbuzz': Property named 'fizzbuzz' is not valid in any stream [every (a=Event(fizzbuzz) -> b=Event(fizzbuzz and foo = 1 and bar = 2))]
Take note that a) global expressions were already declared at this point, b) If I add the pattern containing the global expression aliases in EPL form to the Esper engine, it works.
Any ideas? While it's an option, I'd prefer not to convert from EPStatementObjectModel
to an EPL string everytime I add a new pattern to the engine.
You could inspect a generated object model in a debugger to find out. So in order to generate one, you could call "epadmin.compile("some epl with the expression") and see what comes back.