You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/stream-analytics/stream-analytics-stream-analytics-query-patterns.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ The query design can express simple pass-through logic to move event data from o
17
17
18
18
This article outlines solutions to several common query patterns based on real-world scenarios.
19
19
20
-
## Data Formats
20
+
## Supported Data Formats
21
21
22
22
Azure Stream Analytics supports processing events in CSV, JSON and Avro data formats.
23
23
@@ -339,7 +339,7 @@ For more information, refer to [**COUNT** aggregate function](/stream-analytics-
339
339
340
340
## Calculation over past events
341
341
342
-
The **LAG** function, can be used to look into past events within a time window, this allow past values to be compared against the current event. For example, the current car *Make* can be outputted if it is different from the last car that went through the toll.
342
+
The **LAG** function can be used to look at past events within a time window and compare them against the current event. For example, the current car make can be outputted if it is different from the last car that went through the toll.
343
343
344
344
**Input**:
345
345
@@ -370,7 +370,7 @@ Use **LAG** to peek into the input stream one event back, retrieving the *Make*
370
370
371
371
For more information, refer to [**LAG**](/stream-analytics-query/lag-azure-stream-analytics).
372
372
373
-
## The first event in a window
373
+
## Retrieve the first event in a window
374
374
375
375
**IsFirst** can be used to retrieve the first event in a time window. For example, outputting the first car information at every 10-minute interval.
376
376
@@ -433,9 +433,9 @@ WHERE
433
433
434
434
For more information, refer to [**IsFirst**](/stream-analytics-query/isfirst-azure-stream-analytics).
435
435
436
-
## The last event in a window
436
+
## Return the last event in a window
437
437
438
-
As events are consumed by the system in realtime, there is no function that can determine if an event will be the last one to arrive for that window of time. To achieve this, the input stream needs to be joined with another where the time of an event is the maximum time for all events at that window.
438
+
As events are consumed by the system in real-time, there is no function that can determine if an event will be the last one to arrive for that window of time. To achieve this, the input stream needs to be joined with another where the time of an event is the maximum time for all events at that window.
439
439
440
440
**Input**:
441
441
@@ -482,12 +482,12 @@ FROM
482
482
483
483
The first step on the query finds the maximum time stamp in 10-minute windows, that is the time stamp of the last event for that window. The second step joins the results of the first query with the original stream to find the event that match the last time stamps in each window.
484
484
485
-
**DATEDIFF** is a datespecific function that compares and returns the time different between two DateTime fields, for more information, refer to [date functions](https://docs.microsoft.com/en-us/stream-analytics-query/date-and-time-functions-azure-stream-analytics).
485
+
**DATEDIFF** is a date-specific function that compares and returns the time difference between two DateTime fields, for more information, refer to [date functions](https://docs.microsoft.com/stream-analytics-query/date-and-time-functions-azure-stream-analytics).
486
486
487
487
For more information on joining streams, refer to [**JOIN**](/stream-analytics-query/join-azure-stream-analytics).
488
488
489
489
490
-
## Correlating events in a stream
490
+
## Correlate events in a stream
491
491
492
492
Correlating events in the same stream can be done by looking at past events using the **LAG** function. For example, an output can be generated every time two consecutive cars from the same *Make* go through the toll for the last 90 seconds.
493
493
@@ -525,7 +525,7 @@ The **LAG** function can look into the input stream one event back and retrieve
525
525
526
526
For more information, refer to [LAG](/stream-analytics-query/lag-azure-stream-analytics).
527
527
528
-
## Detecting the duration between events
528
+
## Detect the duration between events
529
529
530
530
The duration of an event can be computed by looking at the last Start event once an End event is received. This query can be useful to determine the time a user spends on a page or a feature.
531
531
@@ -557,11 +557,11 @@ WHERE
557
557
Event ='end'
558
558
```
559
559
560
-
The **LAST** function can be used to retrieve the last event within a specific condition. In this example, the condition is an event of type Start, partitioning the search by **PARTITION BY**[user] and Feature. This way, every user and feature will be treated independently when searching for the Start event. **LIMIT DURATION** limits the search back in time to 1 hour between the End and Start events.
560
+
The **LAST** function can be used to retrieve the last event within a specific condition. In this example, the condition is an event of type Start, partitioning the search by **PARTITION BY** user and feature. This way, every user and feature is treated independently when searching for the Start event. **LIMIT DURATION** limits the search back in time to 1 hour between the End and Start events.
561
561
562
-
## Detecting the duration of a condition
562
+
## Detect the duration of a condition
563
563
564
-
A certain condition can span through multiple events, **LAG** function can also be used to identify the duration of that condition. For example, suppose that a bug resulted in all cars having an incorrect weight (above 20,000 pounds), and the duration of that bug must be computed.
564
+
For conditions that span through multiple events the **LAG** function can be used to identify the duration of that condition. For example, suppose that a bug resulted in all cars having an incorrect weight (above 20,000 pounds), and the duration of that bug must be computed.
565
565
566
566
**Input**:
567
567
@@ -602,11 +602,11 @@ WHERE
602
602
[weight] <20000
603
603
AND previous_weight >20000
604
604
```
605
-
The first **SELECT** statement correlates the current weight measurement with the previous measurement, projecting it together with the current one. The second **SELECT** looks back to the last event where the *previous_weight* is less than 20000, where the current weight is smaller than 20000 and the *previous_weight* of the current event was bigger than 20000.
605
+
The first **SELECT** statement correlates the current weight measurement with the previous measurement, projecting it together with the current measurement. The second **SELECT** looks back to the last event where the *previous_weight* is less than 20000, where the current weight is smaller than 20000 and the *previous_weight* of the current event was bigger than 20000.
606
606
607
-
Sounds complicated but it is simple, the *End_fault* is the current non-faulty event where the previous event was faulty, and the *Start_fault* is the last non-faulty event before that.
607
+
The End_fault is the current non-faulty event where the previous event was faulty, and the Start_fault is the last non-faulty event before that.
608
608
609
-
## Periodically outputting values
609
+
## Periodically output values
610
610
611
611
In case of irregular or missing events, a regular interval output can be generated from a more sparse data input. For example, generate an event every 5 seconds that reports the most recently seen data point.
612
612
@@ -652,9 +652,9 @@ This query generates events every 5 seconds and outputs the last event that was
652
652
653
653
For more information, refer to [Hopping window](/stream-analytics-query/hopping-window-azure-stream-analytics).
654
654
655
-
## Processing events with independent time (Substreams)
655
+
## Process events with independent time (Substreams)
656
656
657
-
Events can arrive late or out of order due to clock skews between event producers, clock skews between partitions, or even network latency.
657
+
Events can arrive late or out of order due to clock skews between event producers, clock skews between partitions, or network latency.
658
658
For example, the device clock for *TollID* 2 is five seconds behind *TollID* 1, and the device clock for *TollID* 3 is ten seconds behind *TollID* 1. A computation can happen independently for each toll, considering only its own clock data as a timestamp.
659
659
660
660
**Input**:
@@ -745,9 +745,9 @@ GROUP BY DeviceId,TumblingWindow(minute, 5)
745
745
746
746
For more information, refer to [COUNT(DISTINCT Time)](/stream-analytics-query/count-azure-stream-analytics).
747
747
748
-
## Session Window
748
+
## Session Windows
749
749
750
-
A Session Window is a window that keeps expanding as events occurs, and closes for computation if no event is received after a specific amount of time or the window reaches its maximum duration.
750
+
A Session Window is a window that keeps expanding as events occur and closes for computation if no event is received after a specific amount of time or if the window reaches its maximum duration.
751
751
This window is particularly useful when computing user interaction data. A window starts when a user starts interacting with the system and closes when no more events are observed, meaning, the user has stopped interacting.
752
752
For example, a user is interacting with a web page where the number of clicks is logged, a Session Window can be used to find out how long the user interacted with the site.
0 commit comments