Esper: Chaining property access and method calls in EPL queries

884 views Asked by At

I am currently struggling to get some Esper EPL queries to work. The queries are looking like this:

select a.center.distance(b.center) as delta
from pattern [
    every-distinct(a.id, b.id) (
        a=org.example.PositionEvent -> b=org.example.PositionEvent
    )
]

When I try to compile this into an EPLStatement via EPAdministrator.createEPL() it throws the following exception:

com.espertech.esper.client.EPStatementException: Error starting statement: Could not load class by name 'a.center', please check imports

If I modify the event classes and the query to read like this

select a.distance(b) as delta
from pattern [
    every-distinct(a.id, b.id) (
        a=org.example.PositionEvent -> b=org.example.PositionEvent
    )
]

it compiles just fine. Esper seems to interpret a.center.distance(...) as a class name followed by a static method invocation, while it interprets a.distance(...) as a method call on the object a.

How can I make Esper interpret my original query as intended (i.e. as a property access followed by a method invocation)?

1

There are 1 answers

0
Simon Lehmann On BEST ANSWER

The solution is actually simple and straightforward (yet a little bit ugly): Use parentheses, just like you do everywhere else when something could be ambiguous. So to make that first query work, write it like this:

select (a.center).distance(b.center) as delta
from pattern [
    every-distinct(a.id, b.id) (
        a=org.example.PositionEvent -> b=org.example.PositionEvent
    )
]

In this case, it actually looks even slightly more readable with the added parentheses.