Sliding Window (Azure Stream Analytics)

 

Updated: February 23, 2017

When using a sliding window, the system is asked to logically consider all possible windows of a given length. As the number of such windows would be infinite, Azure Stream Analytics instead outputs events only for those points in time when the content of the window actually changes, in other words when an event entered or exits the window.

For instance, consider an event stream consisting of the following events:

TimestampName
34A
38B
42C

Using sliding window of length 5 will produce events for windows ending at the following times:

  • 34 - because A entered the window

  • 38 - because B entered the window

  • 39 - because A exited the window

  • 42 - because C entered the window

  • 43 - because B exited the window

No event is produced at time 47 (when C exits the window), since aggregates cannot be computed over empty windows.

Syntax

SLIDINGWINDOW ( timeunit  , windowsize )   
SLIDINGWINDOW ( Duration( timeunit  , windowsize ) )  
  

System_CAPS_ICON_note.jpg Note


The Sliding Window can be used in the above two ways. To allow consistency with the Hopping Window, the Duration function can also be used with all types of windows to specify the window size.

timeunit

Is the unit of time for the windowsize. The following table lists all valid timeunit arguments.

TimeunitAbbreviations
daydd, d
hourhh
minutemi, n
secondss, s
millisecondms
microsecondmcs

windowsize

A big integer which describes the size of the window.

The maximum size of the window in all cases is 7 days.

This example finds all toll booths which have served more than 3 vehicles in the last 5 minutes:

SELECT DateAdd(minute,-5,System.TimeStamp) AS WinStartTime, System.TimeStamp AS WinEndTime, TollId, COUNT(*)   
FROM Input TIMESTAMP BY EntryTime  
GROUP BY TollId, SlidingWindow(minute, 5)  
HAVING COUNT(*) > 3  
  

Show: