Esper EPL 查询时间(t) 和时间(t-1)

发布于 2024-09-29 08:52:15 字数 525 浏览 1 评论 0原文

我正在尝试实现一个 EPL 查询,该查询可以获取 Time(t) & 的平均值。时间(t-1)。

例如:

<块引用>

a) 在前 5 秒(第 0-5 秒)内有 2 个事件,平均值为 12

b) 在接下来的 5 秒(第 5-10 秒)内,有 3 个事件的平均值为 23 ,并且在捕获此信息的 EPL 查询中,我还可以看到前一次的平均值为 12前5秒窗口

我的想法是以最终的 epl 查询具有时间快照的方式交错对象/查询(t) & Time(t-1),如虚拟创建的对象 ScoreInfoBeforeAfter 中所示。但是它不起作用。

任何想法将不胜感激。谢谢。

~~~

// The object being published to the Esper stream:
class ScoreEvent { int score; ... }

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 score; ... }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仄言 2024-10-06 08:52:15

看起来关键字 prior 就是解决方案。

http://esper.codehaus.org/esper -2.1.0/doc/reference/en/html/functionreference.html

请参阅:第 7.1.9 节

根据我在原始帖子中描述的示例,这是我的相应解决方案成立。它似乎工作正常。

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);

..
这很好,因为你可以做这样的事情:

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文