SLIDING WINDOW – Data Sources and Ingestion

A sliding window is illustrated in Figure 3.82 and implemented using the following SQL snippet:

SELECT READINGTYPE, COUNT(*) as Count
FROM brainwaves TIMESTAMP BY CreatedAt
GROUP BY READINGTYPE, SlidingWindow(second, 10)
HAVING COUNT(*)> 3

The second parameter represents the timeunit that the windowsize is applied to, where the windowsize is 10 seconds.

FIGUER 3.82 An Azure Stream Analytics sliding window

The query produces a data record when the count of the same READINGTYPE occurs more than 3 times in under 10 seconds. The darker timeline bars in Figure 3.82 illustrate.

SNAPSHOT WINDOW

A snapshot window is illustrated in Figure 3.83 and implemented using the following SQL snippet:

SELECT READINGTYPE, COUNT(*) as Count
FROM brainwaves TIMESTAMP BY CreatedAt
GROUP BY READINGTYPE, System.Timestamp()

When you are declaring a specific windowing function, a snapshot is not required; instead, when you include System.Timestamp() to the GROUP BY clause, a snapshot window is implied.

FIGUER 3.83 An Azure Stream Analytics snapshot window

The query produces the count of like READINGTYPE values that have the same timestamp.

TUMBLING WINDOW

A tumbling window is illustrated in Figure 3.84 and implemented using the following SQL snippet:

SELECT READINGTYPE, COUNT(*) as Count
FROM brainwaves TIMESTAMP BY CreatedAt
GROUP BY READINGTYPE, TumblingWindow(second, 10)

You might notice a resemblance between tumbling and hopping. The difference is that there is no hopsize and therefore no overlap when it comes to the windowsize.

The second parameter represents the timeunit that the windowsize is applied to, where the windowsize is 10 seconds.

The query produces the count of matching READINGTYPE values every 10 seconds.

In addition to the windowing functions, there are some other built‐in functions worthy of more explanation.

FIGUER 3.84 An Azure Stream Analytics tumbling window

TOPONE

The TopOne aggregate function returns a single record, the first record that matches the group of selected data.

SELECT
 TopOne() OVER (ORDER BY READINGTIMESTAMP) as newestBrainwave
FROM brainwaves
GROUP BY TumblingWindow(second, 10)

Only bigint, float, and datetime data types are supported with the ORDER BY clause.

Write a Comment

Your email address will not be published. Required fields are marked *