real-timeesperepl

How to make esper epl divide section and compare value


I am new using esper. I don't know well about esper epl, so I'm in trouble.

Problem is this.

User define the value section.

For Example,

Level1 : 1~3
Level2 : 4~6
Level3 : 7~9

So when the data come first, check the section and make events. But previous value and new value is same level do nothing (ex. prev value=1, next value=2 These are in same Level1).

In other words, when data is come, check the previous value and level. If they have different level, do something.

Esper Epl can do this? How can I make it?


Solution

  • The "prior" and the "prev" both give you access to the event before a given event. The SQL standard "case when then" is the if-then-else of SQL standard. You could do something like this:

    insert into CategorizedStream select 
     case when value between 1 and 3 then 1 
       when value between 4 and 6 then 2
       when value > 6 then 3
     end as level from SomeEvent;
    
    select * from CategorizedStream(prior(level) != level);
    

    One could probably use prior and case-when to do this in one EPL statement but I think it becomes more readable by using two statements.