0

I'm trying to create a set of EPL statements that allow the engine to alert when a value is or not over a threshold. Another way to understand it is like a 'fence' or geographical fence.

The set of statements must alert when a value enters or leaves this region. For example the next 'fence' value>45 must rise an alert only when value is greater than 45 or, less or equal than 45, but only when a value pass over the threshold.

Here is an I/O example. For DistanceEvents which hold a property distance, and the fence distance>45.

Inputs

DistanceEvents={distance=50}

DistanceEvents={distance=40}

DistanceEvents={distance=33}

DistanceEvents={distance=60}

DistanceEvents={distance=55}

DistanceEvents={distance=45}

DistanceEvents={distance=15}

Outputs

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}

Could someone help me, please?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Pablog1108
  • 87
  • 7
  • 1
    What are the requirements? Your post has only 10 words that describe the requirements. Erase the EPL design stuff - I can't guess your requirements from it. Write down your requirements exactly and with example input and output. Leave the design out it is just confusing. – user3613754 Jul 24 '18 at 05:30
  • Please @user3613754, would you be so kind to review the last edition ?. Thank you very much in advance – Pablog1108 Jul 24 '18 at 12:04

2 Answers2

0

I have come up with below. I have not tested this for you. Use @Audit to debug if it doesn't work. Post the final EPL once you refined it.

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
user3613754
  • 816
  • 1
  • 5
  • 5
  • I had to add a statement for the first incoming event and it's works fine. I have another question related to this. Is it more efficient than to use the select clause with the operator followed by?. By the way, thanks. – Pablog1108 Jul 26 '18 at 12:45
0

This works fine:

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; 
Pablog1108
  • 87
  • 7