如何在Esper中正确创建阈值警报语句

时间:2018-07-23 23:51:54

标签: esper epl nesper

我正在尝试创建一组EPL语句,以允许引擎在值未超过阈值时发出警报。理解它的另一种方式就像是“栅栏”或地理围栏。

这组语句必须在值进入或离开该区域时发出警报。例如,只有当值大于45或小于或等于45时,下一个“围栏”值> 45才必须发出警报,而仅当值超过阈值时才发出警报。

这是一个I / O示例。对于拥有属性距离且围栅距离> 45的DistanceEvents。

输入

DistanceEvents={distance=50}

DistanceEvents={distance=40}

DistanceEvents={distance=33}

DistanceEvents={distance=60}

DistanceEvents={distance=55}

DistanceEvents={distance=45}

DistanceEvents={distance=15}

输出

1 - output= {distance=50.0}
2 - output= {a.distance=50.0, b.distance=40.0}
3 - output= {a.distance=40.0, b.distance=60.0}
4 - output= {a.distance=60.0, b.distance=45.0}

有人可以帮我吗?

2 个答案:

答案 0 :(得分:0)

我在下面提出了。我没有为您测试过。 使用@Audit调试是否无效。优化后,请发布最终的EPL。

create schema Event(distance double);

create table CurrentStateTable(inside boolean);

on Event(distance > 45) as arriving merge CurrentStateTable as cst
  when not matched then 
    insert select false as inside
  when matched and cst.inside
    then insert into AlertStream select arriving.distance
    then update set inside = false;

on Event(distance < 45) as arriving merge CurrentStateTable as cst
  when not matched then 
    insert select true as inside
  when matched and not cst.inside
    then insert into AlertStream select arriving.distance
    then update set inside = true;

select * from AlertStream; // listen here for alerts

答案 1 :(得分:0)

这很好:

create schema DistanceEvents(distance double);
create table CurrentStateTable(inside boolean);

insert into CurrentStateTable select true as inside from DistanceEvents(distance>45)#firstevent;


on DistanceEvents(distance > 45) as arriving merge CurrentStateTable as cst
  when not matched then 
    insert select false as inside
  when matched and cst.inside
    then insert into AlertStream select arriving.distance
    then update set inside = false;


on DistanceEvents(distance <= 45) as arriving merge CurrentStateTable as cst
  when not matched then 
    insert select true as inside
  when matched and not cst.inside
    then insert into AlertStream select arriving.distance
    then update set inside = true;


select * from AlertStream; 
相关问题