Search code examples
espercomplex-event-processing

SQL statement convert to EPL


I am new in NEsper, I need to convert the SQL statement to EPL

Following is my SQL scenario:
1. A is the main table with a field named "Data", B is another table used to stored the distinct "Data" value in A
2. If there is a log come into A with Data value "TEST", we will write the "TEST" to B if there is no "TEST" in B and keep the current time at B
3. At the same time do trigger some events
4. If there are still records come into A with the same Data value "TEST", we will do nothing due to there is already have the "TEST" record in B
5. After 2 hours, we will clear the "TEST" record in B, and loop the step 2~5

I have read the NEsper document, but still can figure out what EPL can achieve the same thing as above do, named Window? Table? or any other keyword Can you give me some advices or hints of what EPL for me? Many thanks.


Solution

  • You could use a "firstunique" window to keep just the first unique item. You can combine that with a time window and thus keep the first unique item for a given time. You can use a subquery to check if an item exists in a named window.