Search code examples
javalambdaesper

Trying to use an Esper Lambda Expression


I am trying to expand on an example from the Esper documentation for the where enumeration method, and having issues. Here is the example in question:

select items.where(i => i.location.x = 0 and i.location.y = 0) as zeroloc
from LocationReport

What I would like to do seems pretty simple. Instead of selecting items that match this expression :

  • I want to select LocationReports that contain at least one item that matches the expression.

  • Do it over a time_batch window (emphasized textnon-batched time window is a possibility as well).

So every n number of seconds I would receive a collection of LocationReports in which each report contains at least one zero location in its items List.

For Reference, here is the structure of the Java objects used in the Esper example:

public class LocationReport { List items; ...

public class Item { String assetId; // passenger or luggage asset id Location location; // (x,y) location boolean luggage; // true if this item is a luggage piece String assetIdPassenger; // if the item is luggage, contains passenger associated ...

public class Location { int x; int y; ...

Background detail : Assume LocationReport is the actual object I am interested in...
Using EPL like in the example above, the where logic works, but the problem is that, in returning only the items member, I do not see the LocationReport class it came from, which contains other properties besides items that my UpdateListener needs.

Also, probably not relevant, but in my case, I am receiving a high rate of messages where many LocationReports are duplicates (or close enough to be considered duplicates), and my where clause will need to make that determination and only forward "new" messages.

Thanks!


Solution

  • You could add the "*" to the select and that gives you the event objects alongside. select *, items.where(...) from LocationReport You could add "output every N seconds" to output. Add "#time(...)" for the time window.