Azure Stream Analytics query to detect missing alive event for a specific deviceId











up vote
1
down vote

favorite












I do not see a way to analyse a stream for the absence of a specific event with azure stream analytics query language.
The stream may contain DeviceAlive and BeaconDetected events containing a DeviceId and in case of BeaconDetected also a BeaconId. Now I want to generate an error event if the DeviceAlive event is missing.



How can I achieve this?
I tried to use reference data with all valid deviceIds.
But I am not allowed to do a linq-wise "contains" query like this



SELECT * FROM
inputStream
WHERE DeviceId IN (SELECT Id FROM DeviceReferenceData)


How can I do such a query. Is this possible by joining the inputStream with the DeviceReferenceData table?
I guess I just do not see the obvious.



The events e.g. are looking like this:



 {
"EventType": "DeviceAlive",
"DeviceId": "winiot-pi",
"EventEnqueuedUtcTime": "2018-11-19T11:00:20.5594584+01:00"
},
{
"EventType": "BeaconDetected",
"BeaconId": "2",
"DeviceId": "winiot-pi",
"EventEnqueuedUtcTime": "2018-11-19T11:00:20.5594584+01:00"
}


Doing a query like this, does not produce the expected result:



SELECT
iothub.*,r.id as rerId
into output
FROM
iothub TIMESTAMP BY EventEnqueuedUtcTime
Left OUTER Join devicesReference r on iothub.DeviceId = r.Id


This only returns a NULL referenceId for every DeviceAlive event. The output in csv:



eventenqueuedutctime;EventType;BeaconId;DeviceId;SignalStrength;rerid
19.11.2018 10:00:20;BeaconDetected;1;winiot-pi;-40;winiot-pi
19.11.2018 10:00:20;BeaconDetected;1;winiot-pi2;-80;winiot-pi2
19.11.2018 10:00:20;ReceiverDeviceAlive;winiot-pi;winiot-pi;;
19.11.2018 10:00:21;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
19.11.2018 10:00:21;BeaconDetected;2;winiot-pi;-80;winiot-pi
19.11.2018 10:00:21;BeaconDetected;2;winiot-pi2;-40;winiot-pi2
19.11.2018 10:00:25;ReceiverDeviceAlive;winiot-pi;winiot-pi;;
19.11.2018 10:00:25;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
19.11.2018 10:00:31;BeaconDetected;1;winiot-pi2;-40;winiot-pi2
19.11.2018 10:00:31;BeaconDetected;1;winiot-pi;-80;winiot-pi
19.11.2018 10:00:32;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:00:32;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:00:33;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
19.11.2018 10:00:36;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:00:46;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
19.11.2018 10:00:46;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:00:57;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
19.11.2018 10:00:57;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:01:07;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
19.11.2018 10:01:07;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:01:20;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
19.11.2018 10:01:30;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;


But what I need is the information on every time window also if the window does not contain any events. We can break it down to that question I guess:
How to query and see also time windows that have none of the desired events.
Is that altogether possible?



Thank you for your help.










share|improve this question




























    up vote
    1
    down vote

    favorite












    I do not see a way to analyse a stream for the absence of a specific event with azure stream analytics query language.
    The stream may contain DeviceAlive and BeaconDetected events containing a DeviceId and in case of BeaconDetected also a BeaconId. Now I want to generate an error event if the DeviceAlive event is missing.



    How can I achieve this?
    I tried to use reference data with all valid deviceIds.
    But I am not allowed to do a linq-wise "contains" query like this



    SELECT * FROM
    inputStream
    WHERE DeviceId IN (SELECT Id FROM DeviceReferenceData)


    How can I do such a query. Is this possible by joining the inputStream with the DeviceReferenceData table?
    I guess I just do not see the obvious.



    The events e.g. are looking like this:



     {
    "EventType": "DeviceAlive",
    "DeviceId": "winiot-pi",
    "EventEnqueuedUtcTime": "2018-11-19T11:00:20.5594584+01:00"
    },
    {
    "EventType": "BeaconDetected",
    "BeaconId": "2",
    "DeviceId": "winiot-pi",
    "EventEnqueuedUtcTime": "2018-11-19T11:00:20.5594584+01:00"
    }


    Doing a query like this, does not produce the expected result:



    SELECT
    iothub.*,r.id as rerId
    into output
    FROM
    iothub TIMESTAMP BY EventEnqueuedUtcTime
    Left OUTER Join devicesReference r on iothub.DeviceId = r.Id


    This only returns a NULL referenceId for every DeviceAlive event. The output in csv:



    eventenqueuedutctime;EventType;BeaconId;DeviceId;SignalStrength;rerid
    19.11.2018 10:00:20;BeaconDetected;1;winiot-pi;-40;winiot-pi
    19.11.2018 10:00:20;BeaconDetected;1;winiot-pi2;-80;winiot-pi2
    19.11.2018 10:00:20;ReceiverDeviceAlive;winiot-pi;winiot-pi;;
    19.11.2018 10:00:21;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
    19.11.2018 10:00:21;BeaconDetected;2;winiot-pi;-80;winiot-pi
    19.11.2018 10:00:21;BeaconDetected;2;winiot-pi2;-40;winiot-pi2
    19.11.2018 10:00:25;ReceiverDeviceAlive;winiot-pi;winiot-pi;;
    19.11.2018 10:00:25;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
    19.11.2018 10:00:31;BeaconDetected;1;winiot-pi2;-40;winiot-pi2
    19.11.2018 10:00:31;BeaconDetected;1;winiot-pi;-80;winiot-pi
    19.11.2018 10:00:32;BeaconDetected;2;winiot-pi;-40;winiot-pi
    19.11.2018 10:00:32;BeaconDetected;2;winiot-pi;-40;winiot-pi
    19.11.2018 10:00:33;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
    19.11.2018 10:00:36;BeaconDetected;2;winiot-pi;-40;winiot-pi
    19.11.2018 10:00:46;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
    19.11.2018 10:00:46;BeaconDetected;2;winiot-pi;-40;winiot-pi
    19.11.2018 10:00:57;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
    19.11.2018 10:00:57;BeaconDetected;2;winiot-pi;-40;winiot-pi
    19.11.2018 10:01:07;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
    19.11.2018 10:01:07;BeaconDetected;2;winiot-pi;-40;winiot-pi
    19.11.2018 10:01:20;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
    19.11.2018 10:01:30;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;


    But what I need is the information on every time window also if the window does not contain any events. We can break it down to that question I guess:
    How to query and see also time windows that have none of the desired events.
    Is that altogether possible?



    Thank you for your help.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I do not see a way to analyse a stream for the absence of a specific event with azure stream analytics query language.
      The stream may contain DeviceAlive and BeaconDetected events containing a DeviceId and in case of BeaconDetected also a BeaconId. Now I want to generate an error event if the DeviceAlive event is missing.



      How can I achieve this?
      I tried to use reference data with all valid deviceIds.
      But I am not allowed to do a linq-wise "contains" query like this



      SELECT * FROM
      inputStream
      WHERE DeviceId IN (SELECT Id FROM DeviceReferenceData)


      How can I do such a query. Is this possible by joining the inputStream with the DeviceReferenceData table?
      I guess I just do not see the obvious.



      The events e.g. are looking like this:



       {
      "EventType": "DeviceAlive",
      "DeviceId": "winiot-pi",
      "EventEnqueuedUtcTime": "2018-11-19T11:00:20.5594584+01:00"
      },
      {
      "EventType": "BeaconDetected",
      "BeaconId": "2",
      "DeviceId": "winiot-pi",
      "EventEnqueuedUtcTime": "2018-11-19T11:00:20.5594584+01:00"
      }


      Doing a query like this, does not produce the expected result:



      SELECT
      iothub.*,r.id as rerId
      into output
      FROM
      iothub TIMESTAMP BY EventEnqueuedUtcTime
      Left OUTER Join devicesReference r on iothub.DeviceId = r.Id


      This only returns a NULL referenceId for every DeviceAlive event. The output in csv:



      eventenqueuedutctime;EventType;BeaconId;DeviceId;SignalStrength;rerid
      19.11.2018 10:00:20;BeaconDetected;1;winiot-pi;-40;winiot-pi
      19.11.2018 10:00:20;BeaconDetected;1;winiot-pi2;-80;winiot-pi2
      19.11.2018 10:00:20;ReceiverDeviceAlive;winiot-pi;winiot-pi;;
      19.11.2018 10:00:21;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
      19.11.2018 10:00:21;BeaconDetected;2;winiot-pi;-80;winiot-pi
      19.11.2018 10:00:21;BeaconDetected;2;winiot-pi2;-40;winiot-pi2
      19.11.2018 10:00:25;ReceiverDeviceAlive;winiot-pi;winiot-pi;;
      19.11.2018 10:00:25;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
      19.11.2018 10:00:31;BeaconDetected;1;winiot-pi2;-40;winiot-pi2
      19.11.2018 10:00:31;BeaconDetected;1;winiot-pi;-80;winiot-pi
      19.11.2018 10:00:32;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:00:32;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:00:33;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
      19.11.2018 10:00:36;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:00:46;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
      19.11.2018 10:00:46;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:00:57;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
      19.11.2018 10:00:57;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:01:07;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
      19.11.2018 10:01:07;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:01:20;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
      19.11.2018 10:01:30;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;


      But what I need is the information on every time window also if the window does not contain any events. We can break it down to that question I guess:
      How to query and see also time windows that have none of the desired events.
      Is that altogether possible?



      Thank you for your help.










      share|improve this question















      I do not see a way to analyse a stream for the absence of a specific event with azure stream analytics query language.
      The stream may contain DeviceAlive and BeaconDetected events containing a DeviceId and in case of BeaconDetected also a BeaconId. Now I want to generate an error event if the DeviceAlive event is missing.



      How can I achieve this?
      I tried to use reference data with all valid deviceIds.
      But I am not allowed to do a linq-wise "contains" query like this



      SELECT * FROM
      inputStream
      WHERE DeviceId IN (SELECT Id FROM DeviceReferenceData)


      How can I do such a query. Is this possible by joining the inputStream with the DeviceReferenceData table?
      I guess I just do not see the obvious.



      The events e.g. are looking like this:



       {
      "EventType": "DeviceAlive",
      "DeviceId": "winiot-pi",
      "EventEnqueuedUtcTime": "2018-11-19T11:00:20.5594584+01:00"
      },
      {
      "EventType": "BeaconDetected",
      "BeaconId": "2",
      "DeviceId": "winiot-pi",
      "EventEnqueuedUtcTime": "2018-11-19T11:00:20.5594584+01:00"
      }


      Doing a query like this, does not produce the expected result:



      SELECT
      iothub.*,r.id as rerId
      into output
      FROM
      iothub TIMESTAMP BY EventEnqueuedUtcTime
      Left OUTER Join devicesReference r on iothub.DeviceId = r.Id


      This only returns a NULL referenceId for every DeviceAlive event. The output in csv:



      eventenqueuedutctime;EventType;BeaconId;DeviceId;SignalStrength;rerid
      19.11.2018 10:00:20;BeaconDetected;1;winiot-pi;-40;winiot-pi
      19.11.2018 10:00:20;BeaconDetected;1;winiot-pi2;-80;winiot-pi2
      19.11.2018 10:00:20;ReceiverDeviceAlive;winiot-pi;winiot-pi;;
      19.11.2018 10:00:21;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
      19.11.2018 10:00:21;BeaconDetected;2;winiot-pi;-80;winiot-pi
      19.11.2018 10:00:21;BeaconDetected;2;winiot-pi2;-40;winiot-pi2
      19.11.2018 10:00:25;ReceiverDeviceAlive;winiot-pi;winiot-pi;;
      19.11.2018 10:00:25;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
      19.11.2018 10:00:31;BeaconDetected;1;winiot-pi2;-40;winiot-pi2
      19.11.2018 10:00:31;BeaconDetected;1;winiot-pi;-80;winiot-pi
      19.11.2018 10:00:32;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:00:32;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:00:33;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
      19.11.2018 10:00:36;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:00:46;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
      19.11.2018 10:00:46;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:00:57;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
      19.11.2018 10:00:57;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:01:07;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
      19.11.2018 10:01:07;BeaconDetected;2;winiot-pi;-40;winiot-pi
      19.11.2018 10:01:20;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
      19.11.2018 10:01:30;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;


      But what I need is the information on every time window also if the window does not contain any events. We can break it down to that question I guess:
      How to query and see also time windows that have none of the desired events.
      Is that altogether possible?



      Thank you for your help.







      azure tsql azure-stream-analytics






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 8:38

























      asked Nov 21 at 16:30









      Micha

      268




      268
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          Based on your requirements, maybe you could use JOIN reference Data to find the deviceId which is missing in the reference data collection. Please try below sql:



          SELECT
          jsoninput.*,r.id as rerId
          into output
          FROM
          jsoninput
          Left OUTER Join jsonreference r on jsoninput.id = r.id
          where r.id is null





          share|improve this answer





















          • I tested it and added some more information to the question.
            – Micha
            Nov 22 at 8:46










          • I guess for detecting "nothing" I will need something like this: how-to-query-for-all-events-and-no-event-scenarios and maybe this how-to-find-absence-of-signal-in-a-stream-analytics-job
            – Micha
            Nov 22 at 9:58




















          up vote
          0
          down vote













          It is a good advice to talk to a colleague, even if he does not fully understand what you are talking about. ;-)
          Here is the solution for generating an error event by detecting the absence of alive events in a 30 second window for a dedicated device with the help of a reference device table.
          Those links helped me a lot understanding more of it:



          azure stream analytics query to detect missing alive event for a specific device



          how to find absence of signal in a stream analytics job



          WITH OneEvent AS /* generate one event per period, any event */
          (
          SELECT
          COUNT(*) As eventCount,
          System.Timestamp as EndOfWindow
          FROM iothub TIMESTAMP BY EventEnqueuedUtcTime
          GROUP BY TumblingWindow(s, 30)
          ),
          AllReferenceDevices AS /* generate one event per deviceId per period */
          (
          SELECT devicesReference.Id, OneEvent.EndOfWindow
          FROM OneEvent JOIN devicesReference
          ON OneEvent.EndOfWindow = OneEvent.EndOfWindow
          ),
          /* Select only the devices where we cannot find an event for */
          DeviceConnectivityErrorDetection AS
          (
          SELECT
          'DeviceConnectivityErrorDetected' AS EventType,
          AllReferenceDevices.Id as FromDeviceId,
          AllReferenceDevices.Id as ToDeviceId,
          AllReferenceDevices.EndOfWindow as EventEnqueuedUtcTime
          FROM
          AllReferenceDevices
          LEFT join iothub TIMESTAMP BY EventEnqueuedUtcTime
          ON DATEDIFF(s, iothub, AllReferenceDevices ) BETWEEN 0 and 30
          AND iothub.DeviceId = AllReferenceDevices.Id
          WHERE iothub IS NULL
          )


          SELECT *
          INTO ReceiverDeviceConnectivityErrorDetectedOutput
          FROM DeviceConnectivityErrorDetection





          share|improve this answer





















            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%2f53416560%2fazure-stream-analytics-query-to-detect-missing-alive-event-for-a-specific-device%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













            Based on your requirements, maybe you could use JOIN reference Data to find the deviceId which is missing in the reference data collection. Please try below sql:



            SELECT
            jsoninput.*,r.id as rerId
            into output
            FROM
            jsoninput
            Left OUTER Join jsonreference r on jsoninput.id = r.id
            where r.id is null





            share|improve this answer





















            • I tested it and added some more information to the question.
              – Micha
              Nov 22 at 8:46










            • I guess for detecting "nothing" I will need something like this: how-to-query-for-all-events-and-no-event-scenarios and maybe this how-to-find-absence-of-signal-in-a-stream-analytics-job
              – Micha
              Nov 22 at 9:58

















            up vote
            1
            down vote













            Based on your requirements, maybe you could use JOIN reference Data to find the deviceId which is missing in the reference data collection. Please try below sql:



            SELECT
            jsoninput.*,r.id as rerId
            into output
            FROM
            jsoninput
            Left OUTER Join jsonreference r on jsoninput.id = r.id
            where r.id is null





            share|improve this answer





















            • I tested it and added some more information to the question.
              – Micha
              Nov 22 at 8:46










            • I guess for detecting "nothing" I will need something like this: how-to-query-for-all-events-and-no-event-scenarios and maybe this how-to-find-absence-of-signal-in-a-stream-analytics-job
              – Micha
              Nov 22 at 9:58















            up vote
            1
            down vote










            up vote
            1
            down vote









            Based on your requirements, maybe you could use JOIN reference Data to find the deviceId which is missing in the reference data collection. Please try below sql:



            SELECT
            jsoninput.*,r.id as rerId
            into output
            FROM
            jsoninput
            Left OUTER Join jsonreference r on jsoninput.id = r.id
            where r.id is null





            share|improve this answer












            Based on your requirements, maybe you could use JOIN reference Data to find the deviceId which is missing in the reference data collection. Please try below sql:



            SELECT
            jsoninput.*,r.id as rerId
            into output
            FROM
            jsoninput
            Left OUTER Join jsonreference r on jsoninput.id = r.id
            where r.id is null






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 at 1:47









            Jay Gong

            7,4231512




            7,4231512












            • I tested it and added some more information to the question.
              – Micha
              Nov 22 at 8:46










            • I guess for detecting "nothing" I will need something like this: how-to-query-for-all-events-and-no-event-scenarios and maybe this how-to-find-absence-of-signal-in-a-stream-analytics-job
              – Micha
              Nov 22 at 9:58




















            • I tested it and added some more information to the question.
              – Micha
              Nov 22 at 8:46










            • I guess for detecting "nothing" I will need something like this: how-to-query-for-all-events-and-no-event-scenarios and maybe this how-to-find-absence-of-signal-in-a-stream-analytics-job
              – Micha
              Nov 22 at 9:58


















            I tested it and added some more information to the question.
            – Micha
            Nov 22 at 8:46




            I tested it and added some more information to the question.
            – Micha
            Nov 22 at 8:46












            I guess for detecting "nothing" I will need something like this: how-to-query-for-all-events-and-no-event-scenarios and maybe this how-to-find-absence-of-signal-in-a-stream-analytics-job
            – Micha
            Nov 22 at 9:58






            I guess for detecting "nothing" I will need something like this: how-to-query-for-all-events-and-no-event-scenarios and maybe this how-to-find-absence-of-signal-in-a-stream-analytics-job
            – Micha
            Nov 22 at 9:58














            up vote
            0
            down vote













            It is a good advice to talk to a colleague, even if he does not fully understand what you are talking about. ;-)
            Here is the solution for generating an error event by detecting the absence of alive events in a 30 second window for a dedicated device with the help of a reference device table.
            Those links helped me a lot understanding more of it:



            azure stream analytics query to detect missing alive event for a specific device



            how to find absence of signal in a stream analytics job



            WITH OneEvent AS /* generate one event per period, any event */
            (
            SELECT
            COUNT(*) As eventCount,
            System.Timestamp as EndOfWindow
            FROM iothub TIMESTAMP BY EventEnqueuedUtcTime
            GROUP BY TumblingWindow(s, 30)
            ),
            AllReferenceDevices AS /* generate one event per deviceId per period */
            (
            SELECT devicesReference.Id, OneEvent.EndOfWindow
            FROM OneEvent JOIN devicesReference
            ON OneEvent.EndOfWindow = OneEvent.EndOfWindow
            ),
            /* Select only the devices where we cannot find an event for */
            DeviceConnectivityErrorDetection AS
            (
            SELECT
            'DeviceConnectivityErrorDetected' AS EventType,
            AllReferenceDevices.Id as FromDeviceId,
            AllReferenceDevices.Id as ToDeviceId,
            AllReferenceDevices.EndOfWindow as EventEnqueuedUtcTime
            FROM
            AllReferenceDevices
            LEFT join iothub TIMESTAMP BY EventEnqueuedUtcTime
            ON DATEDIFF(s, iothub, AllReferenceDevices ) BETWEEN 0 and 30
            AND iothub.DeviceId = AllReferenceDevices.Id
            WHERE iothub IS NULL
            )


            SELECT *
            INTO ReceiverDeviceConnectivityErrorDetectedOutput
            FROM DeviceConnectivityErrorDetection





            share|improve this answer

























              up vote
              0
              down vote













              It is a good advice to talk to a colleague, even if he does not fully understand what you are talking about. ;-)
              Here is the solution for generating an error event by detecting the absence of alive events in a 30 second window for a dedicated device with the help of a reference device table.
              Those links helped me a lot understanding more of it:



              azure stream analytics query to detect missing alive event for a specific device



              how to find absence of signal in a stream analytics job



              WITH OneEvent AS /* generate one event per period, any event */
              (
              SELECT
              COUNT(*) As eventCount,
              System.Timestamp as EndOfWindow
              FROM iothub TIMESTAMP BY EventEnqueuedUtcTime
              GROUP BY TumblingWindow(s, 30)
              ),
              AllReferenceDevices AS /* generate one event per deviceId per period */
              (
              SELECT devicesReference.Id, OneEvent.EndOfWindow
              FROM OneEvent JOIN devicesReference
              ON OneEvent.EndOfWindow = OneEvent.EndOfWindow
              ),
              /* Select only the devices where we cannot find an event for */
              DeviceConnectivityErrorDetection AS
              (
              SELECT
              'DeviceConnectivityErrorDetected' AS EventType,
              AllReferenceDevices.Id as FromDeviceId,
              AllReferenceDevices.Id as ToDeviceId,
              AllReferenceDevices.EndOfWindow as EventEnqueuedUtcTime
              FROM
              AllReferenceDevices
              LEFT join iothub TIMESTAMP BY EventEnqueuedUtcTime
              ON DATEDIFF(s, iothub, AllReferenceDevices ) BETWEEN 0 and 30
              AND iothub.DeviceId = AllReferenceDevices.Id
              WHERE iothub IS NULL
              )


              SELECT *
              INTO ReceiverDeviceConnectivityErrorDetectedOutput
              FROM DeviceConnectivityErrorDetection





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                It is a good advice to talk to a colleague, even if he does not fully understand what you are talking about. ;-)
                Here is the solution for generating an error event by detecting the absence of alive events in a 30 second window for a dedicated device with the help of a reference device table.
                Those links helped me a lot understanding more of it:



                azure stream analytics query to detect missing alive event for a specific device



                how to find absence of signal in a stream analytics job



                WITH OneEvent AS /* generate one event per period, any event */
                (
                SELECT
                COUNT(*) As eventCount,
                System.Timestamp as EndOfWindow
                FROM iothub TIMESTAMP BY EventEnqueuedUtcTime
                GROUP BY TumblingWindow(s, 30)
                ),
                AllReferenceDevices AS /* generate one event per deviceId per period */
                (
                SELECT devicesReference.Id, OneEvent.EndOfWindow
                FROM OneEvent JOIN devicesReference
                ON OneEvent.EndOfWindow = OneEvent.EndOfWindow
                ),
                /* Select only the devices where we cannot find an event for */
                DeviceConnectivityErrorDetection AS
                (
                SELECT
                'DeviceConnectivityErrorDetected' AS EventType,
                AllReferenceDevices.Id as FromDeviceId,
                AllReferenceDevices.Id as ToDeviceId,
                AllReferenceDevices.EndOfWindow as EventEnqueuedUtcTime
                FROM
                AllReferenceDevices
                LEFT join iothub TIMESTAMP BY EventEnqueuedUtcTime
                ON DATEDIFF(s, iothub, AllReferenceDevices ) BETWEEN 0 and 30
                AND iothub.DeviceId = AllReferenceDevices.Id
                WHERE iothub IS NULL
                )


                SELECT *
                INTO ReceiverDeviceConnectivityErrorDetectedOutput
                FROM DeviceConnectivityErrorDetection





                share|improve this answer












                It is a good advice to talk to a colleague, even if he does not fully understand what you are talking about. ;-)
                Here is the solution for generating an error event by detecting the absence of alive events in a 30 second window for a dedicated device with the help of a reference device table.
                Those links helped me a lot understanding more of it:



                azure stream analytics query to detect missing alive event for a specific device



                how to find absence of signal in a stream analytics job



                WITH OneEvent AS /* generate one event per period, any event */
                (
                SELECT
                COUNT(*) As eventCount,
                System.Timestamp as EndOfWindow
                FROM iothub TIMESTAMP BY EventEnqueuedUtcTime
                GROUP BY TumblingWindow(s, 30)
                ),
                AllReferenceDevices AS /* generate one event per deviceId per period */
                (
                SELECT devicesReference.Id, OneEvent.EndOfWindow
                FROM OneEvent JOIN devicesReference
                ON OneEvent.EndOfWindow = OneEvent.EndOfWindow
                ),
                /* Select only the devices where we cannot find an event for */
                DeviceConnectivityErrorDetection AS
                (
                SELECT
                'DeviceConnectivityErrorDetected' AS EventType,
                AllReferenceDevices.Id as FromDeviceId,
                AllReferenceDevices.Id as ToDeviceId,
                AllReferenceDevices.EndOfWindow as EventEnqueuedUtcTime
                FROM
                AllReferenceDevices
                LEFT join iothub TIMESTAMP BY EventEnqueuedUtcTime
                ON DATEDIFF(s, iothub, AllReferenceDevices ) BETWEEN 0 and 30
                AND iothub.DeviceId = AllReferenceDevices.Id
                WHERE iothub IS NULL
                )


                SELECT *
                INTO ReceiverDeviceConnectivityErrorDetectedOutput
                FROM DeviceConnectivityErrorDetection






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 at 11:51









                Micha

                268




                268






























                    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%2f53416560%2fazure-stream-analytics-query-to-detect-missing-alive-event-for-a-specific-device%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

                    Contact image not getting when fetch all contact list from iPhone by CNContact

                    count number of partitions of a set with n elements into k subsets

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks