I am trying to implement an EPL query that can pick up the avg for Time(t) & Time(t-1).
For example:
a) in the first 5 seconds (seconds 0-5) there are 2 events with an avg of 12
b) in the next 5 seconds (seconds 5-10) there are 3 events with an avg of 23 , and in the EPL query that catches this information, I am able to also see the avg of 12 from the previous time window of the first 5 seconds
The idea I have is to stagger the objects/queries in such a way that the final epl query has a snapshot of Time(t) & Time(t-1), as seen in the virtually created object ScoreInfoBeforeAfter . However it's not working.
Any ideas would be greatly appreciated. Thanks.
~~~~
// The object being published to the Esper stream:
class ScoreEvent { int sco开发者_开发问答re; ... }
Looks like the keyword prior is the solution.
http://esper.codehaus.org/esper-2.1.0/doc/reference/en/html/functionreference.html
See: Section 7.1.9
In terms of the example I described in the original post, here's the corresponding solution I found. It seems to be working correctly.
INSERT INTO ScoreInfo
SELECT
'ScoreInfo' as a_Label,
average AS curAvg,
prior(1, average) AS prevAvg
FROM
ScoreEvent.win:time_batch(5 sec).stat:uni(score);
SELECT
*
FROM
ScoreInfo.win:length(1);
..
And then it's nice, because you can do stuff like this:
SELECT
'GT curAvg > prevAvg' as a_Label,
curAvg,
prevAvg
FROM
ScoreInfo.win:length(1)
WHERE
curAvg > prevAvg;
SELECT
'LTE curAvg <= prevAvg' as a_Label,
curAvg,
prevAvg
FROM
ScoreInfo.win:length(1)
WHERE
curAvg <= prevAvg;
精彩评论