Azure Stream Analytics Documentation

Windowing in Azure Stream Analytics

Azure Stream Analytics (ASA) uses the concept of windowing to perform computations over time-series data. Because data streams are continuous, you often need to aggregate or analyze data within specific time boundaries. Windowing allows you to define these boundaries for operations like aggregations (SUM, COUNT, AVG), temporal joins, and detecting patterns over time.

Types of Windows

ASA supports several types of windows, each suited for different analytical scenarios:

1. Tumbling Windows

Tumbling windows are fixed-size, non-overlapping windows. Each event belongs to exactly one tumbling window. They are useful for discrete aggregations over fixed intervals.


SELECT
    System.Timestamp AS WindowEnd,
    COUNT(*) AS EventCount
FROM
    YourInputAlias
GROUP BY
    TumblingWindow(minute, 5)
            

2. Hopping Windows

Hopping windows are fixed-size windows that can overlap. They allow you to analyze data in windows that "hop" forward by a defined amount, enabling more granular analysis without losing data that falls into overlapping periods.


SELECT
    System.Timestamp AS WindowEnd,
    AVG(SensorValue) AS AverageReading
FROM
    YourInputAlias
GROUP BY
    HoppingWindow(minute, 10, 5) -- 10-minute window, hopping by 5 minutes
            

3. Sliding Windows

Sliding windows are fixed-size windows that move forward with each incoming event. An event can belong to multiple sliding windows if it falls within their respective time spans. This is ideal for looking at activity over a rolling period.


SELECT
    System.Timestamp AS WindowEnd,
    SUM(Amount) AS TotalSales
FROM
    SalesStream
GROUP BY
    SlidingWindow(hour, 1) -- 1-hour sliding window
            

4. Session Windows

Session windows group events based on user activity or idle time. A session is defined by a period of activity followed by a period of inactivity. If no events arrive within a specified timeout, the current session ends.


SELECT
    System.Timestamp AS WindowEnd,
    COUNT(*) AS SessionActivityCount
FROM
    ClickStream
GROUP BY
    SessionWindow(minute, 30) -- Session ends after 30 minutes of inactivity
            

Key Concepts

💡 Tip: Choosing the Right Window

The choice of window depends on your business logic. Tumbling windows are simple for fixed intervals, hopping windows for overlapping analysis, sliding windows for rolling metrics, and session windows for tracking user engagement.

Advanced Windowing Scenarios

You can combine windowing with other ASA features such as: