【问题标题】:Esper EPL Query for Time(t) and Time(t-1)Esper EPL 查询 Time(t) 和 Time(t-1)
【发布时间】:2010-10-26 19:33:16
【问题描述】:

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

例如:

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

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

我的想法是错开对象/查询,使最终的 epl 查询具有 Time(t) 和 Time(t-1) 的快照,如虚拟创建的对象 ScoreInfoBeforeAfter 所示。但是它不起作用。

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

~~~~

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

【问题讨论】:

    标签: esper epl


    【解决方案1】:

    看起来关键字 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-21
      • 2023-03-25
      • 2022-12-01
      • 2023-03-07
      • 1970-01-01
      • 2020-04-02
      • 2014-07-10
      相关资源
      最近更新 更多