The Azure Stream Analytics Lag function is reversed

Oetze van den Broek 121 Reputation points
2022-06-08T17:58:24.177+00:00

I am working with Stream analytics for a demo.

I have a physical device that is sendind coordinates as lat and long.
I want to add data about the speed of the device, so basicly take the coordidates difference (with ST_DISTANCE) and the time difference and divide them.

For this i used the query.

SELECT IoTHub.ConnectionDeviceId as deviceid,
EventEnqueuedUtcTime,
LAG(EventEnqueuedUtcTime, 1) OVER (PARTITION BY IoTHub.ConnectionDeviceId LIMIT DURATION(second, 29)) as previous
INTO timediffs
FROM mvpinput

coordinates are left out for now, i know how to add them.

In the editor i now see this as a result.
209567-image.png
Where the first EventEnqueuedUtcTime in the list is the last data point send, But at the first item it can't determine the previous item. Every time has the next item.

So basicly it feels like the LAG function is reversed.

How would i fix this?

Azure Stream Analytics
Azure Stream Analytics
An Azure real-time analytics service designed for mission-critical workloads.
330 questions
{count} votes

Accepted answer
  1. HimanshuSinha-msft 19,381 Reputation points Microsoft Employee
    2022-06-09T21:43:22.977+00:00

    Hello @Oetze van den Broek ,
    Thanks for the question and using MS Q&A platform.

    As we understand the ask here is how to show the record as they arrived , please do let us know if its not accurate. I did some quick test against eventhub and I think the TIMSTAMP BY caluise should help .

    SELECT EHInput.DeviceId as deviceid,
    EventEnqueuedUtcTime,
    LAG(EventEnqueuedUtcTime, 1) OVER (PARTITION BY EHInput.DeviceId LIMIT DURATION(second, 29)) as previous
    into adlsgen2
    FROM EHInput
    TIMESTAMP BY EventEnqueuedUtcTime

    210025-image.png

    Please do let me if you have any queries.
    Thanks
    Himanshu


    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
      • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    0 comments No comments

0 additional answers

Sort by: Most helpful