Select the appropriate windowing functions

  1. Home
  2. Select the appropriate windowing functions

Go back to DP-200 Tutorials

In time-streaming scenarios, performing operations on the data contained in temporal windows is a common pattern. Stream Analytics has native support for windowing functions, enabling developers to author complex stream processing jobs with minimal effort. However, there are five kinds of temporal windows to choose from: Tumbling, Hopping, Sliding, Session, and Snapshot windows. And, you use the window functions in the GROUP BY clause of the query syntax in your Stream Analytics jobs. You can also aggregate events over multiple windows using the Windows() function.

You should know that, all the windowing operations output results at the end of the window. Note that when you start a stream analytics job, you can specify the Job output start time and the system will automatically fetch previous events in the incoming streams to output the first window at the specified time. For example, when you start with the Now option, it will start to emit data immediately. The output of the window will be single event based on the aggregate function used. The output event will have the time stamp of the end of the window and all window functions are defined with a fixed length.

Stream Analytics window functions concepts
Image Source: Microsoft

Tumbling window

Tumbling window functions are used to segment a data stream into distinct time segments and perform a function against them, such as the example below. However, the key differentiators of a Tumbling window are that they repeat, do not overlap, and an event cannot belong to more than one tumbling window.

Stream Analytics tumbling window
Image Source: Microsoft

Hopping window

Hopping window functions hop forward in time by a fixed period. Moreover, it may be easy to think of them as Tumbling windows that can overlap and be emitted more often than the window size. Events can belong to more than one Hopping window result set. Further, to make a Hopping window the same as a Tumbling window, specify the hop size to be the same as the window size.

Stream Analytics hopping window
Image Source: Microsoft
DP-200 practice tests

Sliding window

Sliding windows, unlike Tumbling or Hopping windows, output events only for points in time when the content of the window actually changes. In other words, when an event enters or exits the window. So, every window has at least one event. Similar to Hopping windows, events can belong to more than one sliding window.

Stream Analytics sliding window
Image Source: Microsoft

Session window

Session window functions group events that arrive at similar times, filtering out periods of time where there is no data. However, it has three main parameters: timeout, maximum duration, and partitioning key (optional).

Stream Analytics session windowing
Image Source: Microsoft

Firstly, a session window begins when the first event occurs. And, if another event occurs within the specified timeout from the last ingested event. Then, the window extends to include the new event. Otherwise if no events occur within the timeout, then the window is closed at the timeout.

Further, if events keep occurring within the specified timeout, the session window will keep extending until maximum duration is reached. The maximum duration checking intervals are set to be the same size as the specified max duration. For example, if the max duration is 10, then the checks on if the window exceed maximum duration will happen at t = 0, 10, 20, 30, etc.

Snapshot window

Snapshot windows groups events that have the same timestamp. Unlike other windowing types, which require a specific window function (such as SessionWindow(), you can apply a snapshot window by adding System.Timestamp() to the GROUP BY clause.

Stream Analytics snapshot windowing
Image Source: Microsoft
Select the appropriate windowing functions DP-200 Online course

Reference: Microsoft Documentation

Go back to DP-200 Tutorials

Menu