Skip to content

Commit c33513f

Browse files
authored
Merge pull request #177642 from Fleid/patch-6
Add query in text and explicit outputs
2 parents 22f54ec + 0cd3eaa commit c33513f

File tree

4 files changed

+133
-1
lines changed

4 files changed

+133
-1
lines changed
Loading
Loading
Loading

articles/stream-analytics/stream-analytics-window-functions.md

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,98 @@ The output of the window will be single event based on the aggregate function us
2525

2626
![Stream Analytics tumbling window](media/stream-analytics-window-functions/stream-analytics-window-functions-tumbling-intro.png)
2727

28+
With the following input data (illustrated above):
29+
30+
|Stamp|CreatedAt|TimeZone|
31+
|-|-|-|
32+
|1|2021-10-26T10:15:01|PST|
33+
|5|2021-10-26T10:15:03|PST|
34+
|4|2021-10-26T10:15:06|PST|
35+
|...|...|...|
36+
37+
The following query:
38+
39+
```SQL
40+
SELECT System.Timestamp() as WindowEndTime, TimeZone, COUNT(*) AS Count
41+
FROM TwitterStream TIMESTAMP BY CreatedAt
42+
GROUP BY TimeZone, TumblingWindow(second,10)
43+
```
44+
45+
Will return:
46+
47+
|WindowEndTime|TimeZone|Count|
48+
|-|-|-|
49+
|2021-10-26T10:15:10|PST|5|
50+
|2021-10-26T10:15:20|PST|2|
51+
|2021-10-26T10:15:30|PST|4|
52+
53+
2854
## Hopping window
2955

3056
[**Hopping**](/stream-analytics-query/hopping-window-azure-stream-analytics) window functions hop forward in time by a fixed period. 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. To make a Hopping window the same as a Tumbling window, specify the hop size to be the same as the window size.
3157

3258
![Stream Analytics hopping window](media/stream-analytics-window-functions/stream-analytics-window-functions-hopping-intro.png)
3359

60+
With the following input data (illustrated above):
61+
62+
|Stamp|CreatedAt|Topic|
63+
|-|-|-|
64+
|1|2021-10-26T10:15:01|Streaming|
65+
|5|2021-10-26T10:15:03|Streaming|
66+
|4|2021-10-26T10:15:06|Streaming|
67+
|...|...|...|
68+
69+
The following query:
70+
71+
```SQL
72+
SELECT System.Timestamp() as WindowEndTime, Topic, COUNT(*) AS Count
73+
FROM TwitterStream TIMESTAMP BY CreatedAt
74+
GROUP BY Topic, HoppingWindow(second,10,5)
75+
```
76+
77+
Will return:
78+
79+
|WindowEndTime|Topic|Count|
80+
|-|-|-|
81+
|2021-10-26T10:15:10|Streaming|5|
82+
|2021-10-26T10:15:15|Streaming|3|
83+
|2021-10-26T10:15:20|Streaming|2|
84+
|2021-10-26T10:15:25|Streaming|4|
85+
|2021-10-26T10:15:30|Streaming|4|
86+
87+
3488
## Sliding window
3589

3690
[**Sliding**](/stream-analytics-query/sliding-window-azure-stream-analytics) 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.
3791

3892
![Stream Analytics 10 second sliding window](media/stream-analytics-window-functions/sliding-window-updated.png)
3993

94+
With the following input data (illustrated above):
95+
96+
|Stamp|CreatedAt|Topic|
97+
|-|-|-|
98+
|1|2021-10-26T10:15:10|Streaming|
99+
|5|2021-10-26T10:15:12|Streaming|
100+
|9|2021-10-26T10:15:15|Streaming|
101+
|7|2021-10-26T10:15:15|Streaming|
102+
|8|2021-10-26T10:15:27|Streaming|
103+
104+
The following query:
105+
106+
```SQL
107+
SELECT System.Timestamp() as WindowEndTime, Topic, COUNT(*) AS Count
108+
FROM TwitterStream TIMESTAMP BY CreatedAt
109+
GROUP BY Topic, SlidingWindow(second,10)
110+
HAVING COUNT(*) >=3
111+
```
112+
113+
Will return:
114+
115+
|WindowEndTime|Topic|Count|
116+
|-|-|-|
117+
|2021-10-26T10:15:15|Streaming|4|
118+
|2021-10-26T10:15:20|Streaming|3|
119+
40120
## Session window
41121

42122
[**Session**](/stream-analytics-query/session-window-azure-stream-analytics) window functions group events that arrive at similar times, filtering out periods of time where there is no data. It has three main parameters: timeout, maximum duration, and partitioning key (optional).
@@ -49,11 +129,63 @@ If events keep occurring within the specified timeout, the session window will k
49129

50130
When a partition key is provided, the events are grouped together by the key and session window is applied to each group independently. This partitioning is useful for cases where you need different session windows for different users or devices.
51131

132+
With the following input data (illustrated above):
133+
134+
|Stamp|CreatedAt|Topic|
135+
|-|-|-|
136+
|1|2021-10-26T10:15:01|Streaming|
137+
|2|2021-10-26T10:15:04|Streaming|
138+
|3|2021-10-26T10:15:13|Streaming|
139+
|...|...|...|
140+
141+
The following query:
142+
143+
```SQL
144+
SELECT System.Timestamp() as WindowEndTime, Topic, COUNT(*) AS Count
145+
FROM TwitterStream TIMESTAMP BY CreatedAt
146+
GROUP BY Topic, SessionWindow(second,5,10)
147+
```
148+
149+
Will return:
150+
151+
|WindowEndTime|Topic|Count|
152+
|-|-|-|
153+
|2021-10-26T10:15:09|Streaming|2|
154+
|2021-10-26T10:15:24|Streaming|4|
155+
|2021-10-26T10:15:31|Streaming|2|
156+
|2021-10-26T10:15:39|Streaming|1|
157+
52158
## Snapshot window
53159

54160
[**Snapshot**](/stream-analytics-query/snapshot-window-azure-stream-analytics) windows group events that have the same timestamp. Unlike other windowing types, which require a specific window function (such as [SessionWindow()](/stream-analytics-query/session-window-azure-stream-analytics), you can apply a snapshot window by adding System.Timestamp() to the GROUP BY clause.
55161

56-
![Stream Analytics snapshot window](media/stream-analytics-window-functions/snapshot.png)
162+
![Stream Analytics snapshot window](media/stream-analytics-window-functions/stream-analytics-window-functions-snapshot-intro.png)
163+
164+
With the following input data (illustrated above):
165+
166+
|Stamp|CreatedAt|Topic|
167+
|-|-|-|
168+
|1|2021-10-26T10:15:04|Streaming|
169+
|2|2021-10-26T10:15:04|Streaming|
170+
|3|2021-10-26T10:15:04|Streaming|
171+
|...|...|...|
172+
173+
The following query:
174+
175+
```SQL
176+
SELECT System.Timestamp() as WindowEndTime, Topic, COUNT(*) AS Count
177+
FROM TwitterStream TIMESTAMP BY CreatedAt
178+
GROUP BY Topic, System.Timestamp()
179+
```
180+
181+
Will return:
182+
183+
|WindowEndTime|Topic|Count|
184+
|-|-|-|
185+
|2021-10-26T10:15:04|Streaming|4|
186+
|2021-10-26T10:15:10|Streaming|2|
187+
|2021-10-26T10:15:13|Streaming|1|
188+
|2021-10-26T10:15:22|Streaming|2|
57189

58190
## Next steps
59191
* [Introduction to Azure Stream Analytics](stream-analytics-introduction.md)

0 commit comments

Comments
 (0)