0

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

当值进入或离开该区域时,语句集必须发出警报。例如,下一个 'fence' 值>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}

有人可以帮我吗?

4

2 回答 2

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
于 2018-07-24T16:20:55.780 回答
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; 
于 2018-07-26T12:46:35.673 回答