0

Data structure: {sensorId: 1, temp: 20, timestamp: 1525119377241}

Window Query:

SELECT
    System.Timestamp as WindowEnd,
    sensorId,
    AVG(temp) AS avgTemp,
FROM
    SensorStream TIMESTAMP BY timestamp
GROUP BY
    sensorId,
    SlidingWindow(second, 30)

I would like to calculate in realtime the Slope between the actual avgTemp and the avgTemp 30s before.

Using a tumbling window would work by using LAG(avgTemp, 1) but this would only output every 30s.

TL;DR: I would like to calculate the slope in realtime everytime a new avgTemp is calculated by the sliding window.

Yanis26
  • 247
  • 2
  • 13

1 Answers1

0

Possible duplicate of How to create a delayed sliding window in Azure Stream Analytics

You can do it in two steps. Step 1 computes sliding window, Step 2 computes the slope using LAG.

Vignesh Chandramohan
  • 1,306
  • 10
  • 15
  • That is exactly the issue: Using LAG on a SlidingWindow will give the previous emmited value, which can be less than 1s before and is not predictable because the events can come at any rate. Calculating the slope between t and t-1s is not what I'm trying to do. I'm trying to calculate between t and t-30s – Yanis26 Apr 30 '18 at 20:50
  • So, is there a rate at which events are produced? what if there is no data at t -30s, but there is one at t-29 and another at t-31, which you want to be used? you can use join instead of LAG and specify wiggle to be > 30s, but you also have to provide the upper bound, i.e "and <2min". – Aλeᵡ May 02 '18 at 18:03