How to get a “significant events only”?
up vote
0
down vote
favorite
I have sensors reporting events. Each event has unique device id, and some measurement value, and reporting sequence id (just for debugging).
I want to get only events that are significant (i.e. their measurement value is twice over maximum observed so far), all this based on time - i.e. I want to get the first event, then block N subsequent events for time period T, unless one of those events has very big payload.
I managed to get it done (more or less) in this way:
create schema Alerts(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alerts;
create constant variable int WindowTimeSec = 29;
@Name('Out')
context SegmentedByAsset
select e2 from Alerts.win:time(WindowTimeSec sec).std:firstevent() as e1,
Alerts.std:lastevent() as e2
where e2.seq = e1.seq or e2.load > 2* (select max(prev(load))
from Alerts.win:time(WindowTimeSec sec))
- First - that's ugly.
- Second - I have a "gut feeling" that it won't be very efficient.
- Third - if the condition for special events detection gets more complex, simple subquery won't work (i.e. in addition to load event will have more attributes, like time and type, and I'll need to compare time and type of the event with max load to decide if the last event should be published or blocked).
What would be the recommended pattern to do it ?
10x
esper
add a comment |
up vote
0
down vote
favorite
I have sensors reporting events. Each event has unique device id, and some measurement value, and reporting sequence id (just for debugging).
I want to get only events that are significant (i.e. their measurement value is twice over maximum observed so far), all this based on time - i.e. I want to get the first event, then block N subsequent events for time period T, unless one of those events has very big payload.
I managed to get it done (more or less) in this way:
create schema Alerts(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alerts;
create constant variable int WindowTimeSec = 29;
@Name('Out')
context SegmentedByAsset
select e2 from Alerts.win:time(WindowTimeSec sec).std:firstevent() as e1,
Alerts.std:lastevent() as e2
where e2.seq = e1.seq or e2.load > 2* (select max(prev(load))
from Alerts.win:time(WindowTimeSec sec))
- First - that's ugly.
- Second - I have a "gut feeling" that it won't be very efficient.
- Third - if the condition for special events detection gets more complex, simple subquery won't work (i.e. in addition to load event will have more attributes, like time and type, and I'll need to compare time and type of the event with max load to decide if the last event should be published or blocked).
What would be the recommended pattern to do it ?
10x
esper
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have sensors reporting events. Each event has unique device id, and some measurement value, and reporting sequence id (just for debugging).
I want to get only events that are significant (i.e. their measurement value is twice over maximum observed so far), all this based on time - i.e. I want to get the first event, then block N subsequent events for time period T, unless one of those events has very big payload.
I managed to get it done (more or less) in this way:
create schema Alerts(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alerts;
create constant variable int WindowTimeSec = 29;
@Name('Out')
context SegmentedByAsset
select e2 from Alerts.win:time(WindowTimeSec sec).std:firstevent() as e1,
Alerts.std:lastevent() as e2
where e2.seq = e1.seq or e2.load > 2* (select max(prev(load))
from Alerts.win:time(WindowTimeSec sec))
- First - that's ugly.
- Second - I have a "gut feeling" that it won't be very efficient.
- Third - if the condition for special events detection gets more complex, simple subquery won't work (i.e. in addition to load event will have more attributes, like time and type, and I'll need to compare time and type of the event with max load to decide if the last event should be published or blocked).
What would be the recommended pattern to do it ?
10x
esper
I have sensors reporting events. Each event has unique device id, and some measurement value, and reporting sequence id (just for debugging).
I want to get only events that are significant (i.e. their measurement value is twice over maximum observed so far), all this based on time - i.e. I want to get the first event, then block N subsequent events for time period T, unless one of those events has very big payload.
I managed to get it done (more or less) in this way:
create schema Alerts(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alerts;
create constant variable int WindowTimeSec = 29;
@Name('Out')
context SegmentedByAsset
select e2 from Alerts.win:time(WindowTimeSec sec).std:firstevent() as e1,
Alerts.std:lastevent() as e2
where e2.seq = e1.seq or e2.load > 2* (select max(prev(load))
from Alerts.win:time(WindowTimeSec sec))
- First - that's ugly.
- Second - I have a "gut feeling" that it won't be very efficient.
- Third - if the condition for special events detection gets more complex, simple subquery won't work (i.e. in addition to load event will have more attributes, like time and type, and I'll need to compare time and type of the event with max load to decide if the last event should be published or blocked).
What would be the recommended pattern to do it ?
10x
esper
esper
asked Nov 19 at 17:16
Alex Arlievsky
183
183
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
You can design a table row to hold the aggregation and use @priority to say when it is updated.
create schema Alert(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alert;
create constant variable int WindowTimeSec = 29;
context SegmentedByAsset create table LoadAggTable(maxLoad max(double));
// select first (priority is 1)
@name('out') @priority(1) context SegmentedByAsset select * from Alert where load > LoadAggTable.maxLoad;
// update table next (priority is 0)
@priority(0) context SegmentedByAsset into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
The table could hold "maxBy" which is the event that contributed the max or other aggregations as well.
This table will hold event with the maximal load that ever arrived, or it will be subject to WindowTime sliding window ? I see that table update statement uses window with time limit, but I don't understand why event that was had maximal load now will be removed from the table when time period expires (assuming it is still bigger than everything arrived after it)? I came out with similar solution but using named window:context SegmentedByAsset create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
– Alex Arlievsky
Nov 20 at 8:01
1
The table is subject to time window sliding. It carries the current aggregation value in the column.
– user650839
Nov 20 at 12:40
context SegmentedByAsset create table LoadAggTable (myMaxByEver maxbyever(load) @type(Alerts)); @name("TableSel") @priority(1) context SegmentedByAsset select LoadAggTable.myMaxByEver.load , * from Alerts where load > 2*LoadAggTable.myMaxByEver.load or LoadAggTable.myMaxByEver is null; @priority(0) context SegmentedByAsset into table LoadAggTable select feeder, max(load), seq from Alerts#time(WindowTimeSec sec); I don't understand the syntax of "into table" insertion statement for table with "maxever" aggregate column. Can you explain how it should be constructed ? 10x.
– Alex Arlievsky
Nov 20 at 16:22
I just want to have ALL event data available in the LoadAggTable, not only value of the load. If I declare table as: LoadAggTable (feeder string, load double, seq int, maxLoad max(double)); and update it using into table LoadAggTable select feeder, load, seq, max(load) as maxLoad all columns except maxLoad are nulls, so I suspect I do something wrong here :)
– Alex Arlievsky
Nov 20 at 16:28
I don't understand what makes table subject to time window sliding. into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
– Alex Arlievsky
Nov 21 at 7:41
|
show 1 more comment
up vote
0
down vote
I came out with something based on Windows (previous answer, suggesting to use Tables with aggregation columns, may work, but I don't understand why :))
create schema Alerts(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alerts;
create constant variable int WindowTimeSec = 12;
context SegmentedByAsset
create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
@Name('Select')
context SegmentedByAsset
select e2 from Alerts.std:lastevent() as e2 where (select count(*) from
AlertsWindow) = 0 or e2.load > 2* (select load from AlertsWindow);
@Name('Insert')
context SegmentedByAsset
insert into AlertsWindow select * from Alerts;
Essentially it just keeps event with maximal load for the past WindowTimeSec period in the named window, if new event has bigger load it gets published, if time period expired and named window is empty - any new event gets published. It is not exactly what I had in mind, but for this specific use case it would work as well, and "bypass condition" can have any complexity, as the complete event data is kept in the window.
1
Why use a last-event-window? This could just be "select e2 from Alerts as e2 where"
– user650839
Nov 20 at 12:43
You are right, it is just leftovers from my experiments
– Alex Arlievsky
Nov 20 at 16:19
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You can design a table row to hold the aggregation and use @priority to say when it is updated.
create schema Alert(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alert;
create constant variable int WindowTimeSec = 29;
context SegmentedByAsset create table LoadAggTable(maxLoad max(double));
// select first (priority is 1)
@name('out') @priority(1) context SegmentedByAsset select * from Alert where load > LoadAggTable.maxLoad;
// update table next (priority is 0)
@priority(0) context SegmentedByAsset into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
The table could hold "maxBy" which is the event that contributed the max or other aggregations as well.
This table will hold event with the maximal load that ever arrived, or it will be subject to WindowTime sliding window ? I see that table update statement uses window with time limit, but I don't understand why event that was had maximal load now will be removed from the table when time period expires (assuming it is still bigger than everything arrived after it)? I came out with similar solution but using named window:context SegmentedByAsset create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
– Alex Arlievsky
Nov 20 at 8:01
1
The table is subject to time window sliding. It carries the current aggregation value in the column.
– user650839
Nov 20 at 12:40
context SegmentedByAsset create table LoadAggTable (myMaxByEver maxbyever(load) @type(Alerts)); @name("TableSel") @priority(1) context SegmentedByAsset select LoadAggTable.myMaxByEver.load , * from Alerts where load > 2*LoadAggTable.myMaxByEver.load or LoadAggTable.myMaxByEver is null; @priority(0) context SegmentedByAsset into table LoadAggTable select feeder, max(load), seq from Alerts#time(WindowTimeSec sec); I don't understand the syntax of "into table" insertion statement for table with "maxever" aggregate column. Can you explain how it should be constructed ? 10x.
– Alex Arlievsky
Nov 20 at 16:22
I just want to have ALL event data available in the LoadAggTable, not only value of the load. If I declare table as: LoadAggTable (feeder string, load double, seq int, maxLoad max(double)); and update it using into table LoadAggTable select feeder, load, seq, max(load) as maxLoad all columns except maxLoad are nulls, so I suspect I do something wrong here :)
– Alex Arlievsky
Nov 20 at 16:28
I don't understand what makes table subject to time window sliding. into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
– Alex Arlievsky
Nov 21 at 7:41
|
show 1 more comment
up vote
1
down vote
You can design a table row to hold the aggregation and use @priority to say when it is updated.
create schema Alert(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alert;
create constant variable int WindowTimeSec = 29;
context SegmentedByAsset create table LoadAggTable(maxLoad max(double));
// select first (priority is 1)
@name('out') @priority(1) context SegmentedByAsset select * from Alert where load > LoadAggTable.maxLoad;
// update table next (priority is 0)
@priority(0) context SegmentedByAsset into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
The table could hold "maxBy" which is the event that contributed the max or other aggregations as well.
This table will hold event with the maximal load that ever arrived, or it will be subject to WindowTime sliding window ? I see that table update statement uses window with time limit, but I don't understand why event that was had maximal load now will be removed from the table when time period expires (assuming it is still bigger than everything arrived after it)? I came out with similar solution but using named window:context SegmentedByAsset create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
– Alex Arlievsky
Nov 20 at 8:01
1
The table is subject to time window sliding. It carries the current aggregation value in the column.
– user650839
Nov 20 at 12:40
context SegmentedByAsset create table LoadAggTable (myMaxByEver maxbyever(load) @type(Alerts)); @name("TableSel") @priority(1) context SegmentedByAsset select LoadAggTable.myMaxByEver.load , * from Alerts where load > 2*LoadAggTable.myMaxByEver.load or LoadAggTable.myMaxByEver is null; @priority(0) context SegmentedByAsset into table LoadAggTable select feeder, max(load), seq from Alerts#time(WindowTimeSec sec); I don't understand the syntax of "into table" insertion statement for table with "maxever" aggregate column. Can you explain how it should be constructed ? 10x.
– Alex Arlievsky
Nov 20 at 16:22
I just want to have ALL event data available in the LoadAggTable, not only value of the load. If I declare table as: LoadAggTable (feeder string, load double, seq int, maxLoad max(double)); and update it using into table LoadAggTable select feeder, load, seq, max(load) as maxLoad all columns except maxLoad are nulls, so I suspect I do something wrong here :)
– Alex Arlievsky
Nov 20 at 16:28
I don't understand what makes table subject to time window sliding. into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
– Alex Arlievsky
Nov 21 at 7:41
|
show 1 more comment
up vote
1
down vote
up vote
1
down vote
You can design a table row to hold the aggregation and use @priority to say when it is updated.
create schema Alert(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alert;
create constant variable int WindowTimeSec = 29;
context SegmentedByAsset create table LoadAggTable(maxLoad max(double));
// select first (priority is 1)
@name('out') @priority(1) context SegmentedByAsset select * from Alert where load > LoadAggTable.maxLoad;
// update table next (priority is 0)
@priority(0) context SegmentedByAsset into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
The table could hold "maxBy" which is the event that contributed the max or other aggregations as well.
You can design a table row to hold the aggregation and use @priority to say when it is updated.
create schema Alert(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alert;
create constant variable int WindowTimeSec = 29;
context SegmentedByAsset create table LoadAggTable(maxLoad max(double));
// select first (priority is 1)
@name('out') @priority(1) context SegmentedByAsset select * from Alert where load > LoadAggTable.maxLoad;
// update table next (priority is 0)
@priority(0) context SegmentedByAsset into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
The table could hold "maxBy" which is the event that contributed the max or other aggregations as well.
answered Nov 19 at 22:00
user650839
2,105187
2,105187
This table will hold event with the maximal load that ever arrived, or it will be subject to WindowTime sliding window ? I see that table update statement uses window with time limit, but I don't understand why event that was had maximal load now will be removed from the table when time period expires (assuming it is still bigger than everything arrived after it)? I came out with similar solution but using named window:context SegmentedByAsset create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
– Alex Arlievsky
Nov 20 at 8:01
1
The table is subject to time window sliding. It carries the current aggregation value in the column.
– user650839
Nov 20 at 12:40
context SegmentedByAsset create table LoadAggTable (myMaxByEver maxbyever(load) @type(Alerts)); @name("TableSel") @priority(1) context SegmentedByAsset select LoadAggTable.myMaxByEver.load , * from Alerts where load > 2*LoadAggTable.myMaxByEver.load or LoadAggTable.myMaxByEver is null; @priority(0) context SegmentedByAsset into table LoadAggTable select feeder, max(load), seq from Alerts#time(WindowTimeSec sec); I don't understand the syntax of "into table" insertion statement for table with "maxever" aggregate column. Can you explain how it should be constructed ? 10x.
– Alex Arlievsky
Nov 20 at 16:22
I just want to have ALL event data available in the LoadAggTable, not only value of the load. If I declare table as: LoadAggTable (feeder string, load double, seq int, maxLoad max(double)); and update it using into table LoadAggTable select feeder, load, seq, max(load) as maxLoad all columns except maxLoad are nulls, so I suspect I do something wrong here :)
– Alex Arlievsky
Nov 20 at 16:28
I don't understand what makes table subject to time window sliding. into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
– Alex Arlievsky
Nov 21 at 7:41
|
show 1 more comment
This table will hold event with the maximal load that ever arrived, or it will be subject to WindowTime sliding window ? I see that table update statement uses window with time limit, but I don't understand why event that was had maximal load now will be removed from the table when time period expires (assuming it is still bigger than everything arrived after it)? I came out with similar solution but using named window:context SegmentedByAsset create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
– Alex Arlievsky
Nov 20 at 8:01
1
The table is subject to time window sliding. It carries the current aggregation value in the column.
– user650839
Nov 20 at 12:40
context SegmentedByAsset create table LoadAggTable (myMaxByEver maxbyever(load) @type(Alerts)); @name("TableSel") @priority(1) context SegmentedByAsset select LoadAggTable.myMaxByEver.load , * from Alerts where load > 2*LoadAggTable.myMaxByEver.load or LoadAggTable.myMaxByEver is null; @priority(0) context SegmentedByAsset into table LoadAggTable select feeder, max(load), seq from Alerts#time(WindowTimeSec sec); I don't understand the syntax of "into table" insertion statement for table with "maxever" aggregate column. Can you explain how it should be constructed ? 10x.
– Alex Arlievsky
Nov 20 at 16:22
I just want to have ALL event data available in the LoadAggTable, not only value of the load. If I declare table as: LoadAggTable (feeder string, load double, seq int, maxLoad max(double)); and update it using into table LoadAggTable select feeder, load, seq, max(load) as maxLoad all columns except maxLoad are nulls, so I suspect I do something wrong here :)
– Alex Arlievsky
Nov 20 at 16:28
I don't understand what makes table subject to time window sliding. into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
– Alex Arlievsky
Nov 21 at 7:41
This table will hold event with the maximal load that ever arrived, or it will be subject to WindowTime sliding window ? I see that table update statement uses window with time limit, but I don't understand why event that was had maximal load now will be removed from the table when time period expires (assuming it is still bigger than everything arrived after it)? I came out with similar solution but using named window:
context SegmentedByAsset create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
– Alex Arlievsky
Nov 20 at 8:01
This table will hold event with the maximal load that ever arrived, or it will be subject to WindowTime sliding window ? I see that table update statement uses window with time limit, but I don't understand why event that was had maximal load now will be removed from the table when time period expires (assuming it is still bigger than everything arrived after it)? I came out with similar solution but using named window:
context SegmentedByAsset create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
– Alex Arlievsky
Nov 20 at 8:01
1
1
The table is subject to time window sliding. It carries the current aggregation value in the column.
– user650839
Nov 20 at 12:40
The table is subject to time window sliding. It carries the current aggregation value in the column.
– user650839
Nov 20 at 12:40
context SegmentedByAsset create table LoadAggTable (myMaxByEver maxbyever(load) @type(Alerts)); @name("TableSel") @priority(1) context SegmentedByAsset select LoadAggTable.myMaxByEver.load , * from Alerts where load > 2*LoadAggTable.myMaxByEver.load or LoadAggTable.myMaxByEver is null; @priority(0) context SegmentedByAsset into table LoadAggTable select feeder, max(load), seq from Alerts#time(WindowTimeSec sec); I don't understand the syntax of "into table" insertion statement for table with "maxever" aggregate column. Can you explain how it should be constructed ? 10x.
– Alex Arlievsky
Nov 20 at 16:22
context SegmentedByAsset create table LoadAggTable (myMaxByEver maxbyever(load) @type(Alerts)); @name("TableSel") @priority(1) context SegmentedByAsset select LoadAggTable.myMaxByEver.load , * from Alerts where load > 2*LoadAggTable.myMaxByEver.load or LoadAggTable.myMaxByEver is null; @priority(0) context SegmentedByAsset into table LoadAggTable select feeder, max(load), seq from Alerts#time(WindowTimeSec sec); I don't understand the syntax of "into table" insertion statement for table with "maxever" aggregate column. Can you explain how it should be constructed ? 10x.
– Alex Arlievsky
Nov 20 at 16:22
I just want to have ALL event data available in the LoadAggTable, not only value of the load. If I declare table as: LoadAggTable (feeder string, load double, seq int, maxLoad max(double)); and update it using into table LoadAggTable select feeder, load, seq, max(load) as maxLoad all columns except maxLoad are nulls, so I suspect I do something wrong here :)
– Alex Arlievsky
Nov 20 at 16:28
I just want to have ALL event data available in the LoadAggTable, not only value of the load. If I declare table as: LoadAggTable (feeder string, load double, seq int, maxLoad max(double)); and update it using into table LoadAggTable select feeder, load, seq, max(load) as maxLoad all columns except maxLoad are nulls, so I suspect I do something wrong here :)
– Alex Arlievsky
Nov 20 at 16:28
I don't understand what makes table subject to time window sliding. into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
– Alex Arlievsky
Nov 21 at 7:41
I don't understand what makes table subject to time window sliding. into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);
– Alex Arlievsky
Nov 21 at 7:41
|
show 1 more comment
up vote
0
down vote
I came out with something based on Windows (previous answer, suggesting to use Tables with aggregation columns, may work, but I don't understand why :))
create schema Alerts(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alerts;
create constant variable int WindowTimeSec = 12;
context SegmentedByAsset
create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
@Name('Select')
context SegmentedByAsset
select e2 from Alerts.std:lastevent() as e2 where (select count(*) from
AlertsWindow) = 0 or e2.load > 2* (select load from AlertsWindow);
@Name('Insert')
context SegmentedByAsset
insert into AlertsWindow select * from Alerts;
Essentially it just keeps event with maximal load for the past WindowTimeSec period in the named window, if new event has bigger load it gets published, if time period expired and named window is empty - any new event gets published. It is not exactly what I had in mind, but for this specific use case it would work as well, and "bypass condition" can have any complexity, as the complete event data is kept in the window.
1
Why use a last-event-window? This could just be "select e2 from Alerts as e2 where"
– user650839
Nov 20 at 12:43
You are right, it is just leftovers from my experiments
– Alex Arlievsky
Nov 20 at 16:19
add a comment |
up vote
0
down vote
I came out with something based on Windows (previous answer, suggesting to use Tables with aggregation columns, may work, but I don't understand why :))
create schema Alerts(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alerts;
create constant variable int WindowTimeSec = 12;
context SegmentedByAsset
create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
@Name('Select')
context SegmentedByAsset
select e2 from Alerts.std:lastevent() as e2 where (select count(*) from
AlertsWindow) = 0 or e2.load > 2* (select load from AlertsWindow);
@Name('Insert')
context SegmentedByAsset
insert into AlertsWindow select * from Alerts;
Essentially it just keeps event with maximal load for the past WindowTimeSec period in the named window, if new event has bigger load it gets published, if time period expired and named window is empty - any new event gets published. It is not exactly what I had in mind, but for this specific use case it would work as well, and "bypass condition" can have any complexity, as the complete event data is kept in the window.
1
Why use a last-event-window? This could just be "select e2 from Alerts as e2 where"
– user650839
Nov 20 at 12:43
You are right, it is just leftovers from my experiments
– Alex Arlievsky
Nov 20 at 16:19
add a comment |
up vote
0
down vote
up vote
0
down vote
I came out with something based on Windows (previous answer, suggesting to use Tables with aggregation columns, may work, but I don't understand why :))
create schema Alerts(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alerts;
create constant variable int WindowTimeSec = 12;
context SegmentedByAsset
create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
@Name('Select')
context SegmentedByAsset
select e2 from Alerts.std:lastevent() as e2 where (select count(*) from
AlertsWindow) = 0 or e2.load > 2* (select load from AlertsWindow);
@Name('Insert')
context SegmentedByAsset
insert into AlertsWindow select * from Alerts;
Essentially it just keeps event with maximal load for the past WindowTimeSec period in the named window, if new event has bigger load it gets published, if time period expired and named window is empty - any new event gets published. It is not exactly what I had in mind, but for this specific use case it would work as well, and "bypass condition" can have any complexity, as the complete event data is kept in the window.
I came out with something based on Windows (previous answer, suggesting to use Tables with aggregation columns, may work, but I don't understand why :))
create schema Alerts(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alerts;
create constant variable int WindowTimeSec = 12;
context SegmentedByAsset
create window AlertsWindow.win:time(WindowTimeSec sec).ext:sort(1, load desc) as Alerts;
@Name('Select')
context SegmentedByAsset
select e2 from Alerts.std:lastevent() as e2 where (select count(*) from
AlertsWindow) = 0 or e2.load > 2* (select load from AlertsWindow);
@Name('Insert')
context SegmentedByAsset
insert into AlertsWindow select * from Alerts;
Essentially it just keeps event with maximal load for the past WindowTimeSec period in the named window, if new event has bigger load it gets published, if time period expired and named window is empty - any new event gets published. It is not exactly what I had in mind, but for this specific use case it would work as well, and "bypass condition" can have any complexity, as the complete event data is kept in the window.
answered Nov 20 at 8:43
Alex Arlievsky
183
183
1
Why use a last-event-window? This could just be "select e2 from Alerts as e2 where"
– user650839
Nov 20 at 12:43
You are right, it is just leftovers from my experiments
– Alex Arlievsky
Nov 20 at 16:19
add a comment |
1
Why use a last-event-window? This could just be "select e2 from Alerts as e2 where"
– user650839
Nov 20 at 12:43
You are right, it is just leftovers from my experiments
– Alex Arlievsky
Nov 20 at 16:19
1
1
Why use a last-event-window? This could just be "select e2 from Alerts as e2 where"
– user650839
Nov 20 at 12:43
Why use a last-event-window? This could just be "select e2 from Alerts as e2 where"
– user650839
Nov 20 at 12:43
You are right, it is just leftovers from my experiments
– Alex Arlievsky
Nov 20 at 16:19
You are right, it is just leftovers from my experiments
– Alex Arlievsky
Nov 20 at 16:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379655%2fhow-to-get-a-significant-events-only%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown