问题
I'm new in Esper. Can anyone help me define the EPL statement to catch the event when the following situation occurs:
- Assumming that there are events with 3 attributes - (string)Symbol, (boolean)Value, (datetime)Timestamp. For example event1 (Symbol-apple, Value-true, Timestamp- 2020.10.07 14:00:00), event2 (Symbol-orange, Value-true, Timestamp- 2020.10.07 14:00:00) and event3 (Symbol-banana, Value-false, Timestamp- 2020.10.07 14:00:00). If they have same (or almost the same) Timestamp only one of them can have attribute - Value as true. In this example event2 matchs the requirement and should be captured.
How can I define the statement to catch it?
Thanks for any help.
Narsu
回答1:
The "window" is an aggregation function (see manual) returns the events. The enumeration methods (selectfrom, countof, see manual) are for filtering and selecting. Something like this.
select window(*).selectFrom(v => v.value=true) as eventWithTrueFlag
from Event#length(3)
having window(*).countOf(v => v.value=true)=1 and
prev(1, timestamp)=timestamp and prev(2, timestamp)=timestamp
"Event" is your event type. You didn't say what your event type is named. "Prev" is the previous function (see manual).
来源:https://stackoverflow.com/questions/64244157/esper-nesper-epl-event-statement