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










share|improve this question


























    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










    share|improve this question
























      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










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 at 17:16









      Alex Arlievsky

      183




      183
























          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.






          share|improve this answer





















          • 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


















          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.






          share|improve this answer

















          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          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.






          share|improve this answer





















          • 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















          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.






          share|improve this answer





















          • 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













          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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












          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.






          share|improve this answer

















          • 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















          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.






          share|improve this answer

















          • 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













          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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














          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin