|
1 | 1 | --- |
2 | 2 | title: Common query patterns in Azure Stream Analytics |
3 | | -description: This article describes several common query patterns and designs that are useful in Azure Stream Analytics jobs. |
| 3 | +description: This article describes several common query patterns and designs that are useful in Azure Stream Analytics jobs and Fabric Eventstream. |
4 | 4 | ms.service: azure-stream-analytics |
5 | 5 | ms.topic: how-to |
6 | | -ms.date: 12/17/2024 |
| 6 | +ms.date: 03/04/2026 |
7 | 7 | ms.custom: devx-track-js |
8 | 8 | --- |
9 | 9 |
|
10 | | -# Common query patterns in Azure Stream Analytics |
| 10 | +# Common query patterns in Azure Stream Analytics and Fabric Eventstream |
11 | 11 |
|
12 | | -Queries in Azure Stream Analytics are expressed in an SQL-like query language. The language constructs are documented in the [Stream Analytics query language reference](/stream-analytics-query/stream-analytics-query-language-reference) guide. |
| 12 | +[!INCLUDE [stream-analytics-fabric-event-stream-query-language](./includes/stream-analytics-fabric-event-stream-query-language.md)] |
| 13 | + |
| 14 | +Queries in Azure Stream Analytics are expressed in a SQL-like query language. The language constructs are documented in the [Stream Analytics query language reference](/stream-analytics-query/stream-analytics-query-language-reference) guide. |
13 | 15 |
|
14 | 16 | The query design can express simple pass-through logic to move event data from one input stream into an output data store, or it can do rich pattern matching and temporal analysis to calculate aggregates over various time windows as in the [Build an IoT solution by using Stream Analytics](stream-analytics-build-an-iot-solution-using-stream-analytics.md) guide. You can join data from multiple inputs to combine streaming events, and you can do lookups against static reference data to enrich the event values. You can also write data to multiple outputs. |
15 | 17 |
|
|
83 | 85 | ``` |
84 | 86 |
|
85 | 87 |
|
86 | | -The **INTO** clause tells the Stream Analytics service which of the outputs to write the data to. The first **SELECT** defines a pass-through query that receives data from the input and sends it to the output named **ArchiveOutput**. The second query aggregates and filters data before sending the results to a downstream alerting system output called **AlertOutput**. |
| 88 | +The **INTO** clause tells the Stream Analytics service, which of the outputs to write the data to. The first **SELECT** defines a pass-through query that receives data from the input and sends it to the output named **ArchiveOutput**. The second query aggregates and filters data before sending the results to a downstream alerting system output called **AlertOutput**. |
87 | 89 |
|
88 | 90 | The **WITH** clause can be used to define multiple subquery blocks. This option has the benefit of opening fewer readers to the input source. |
89 | 91 |
|
@@ -115,7 +117,7 @@ For more information, see [**WITH** clause](/stream-analytics-query/with-azure-s |
115 | 117 |
|
116 | 118 | ## Simple pass-through query |
117 | 119 |
|
118 | | -A simple pass-through query can be used to copy the input stream data into the output. For example, if a stream of data containing real-time vehicle information needs to be saved in an SQL database for later analysis, a simple pass-through query does the job. |
| 120 | +A simple pass-through query can be used to copy the input stream data into the output. For example, if a stream of data containing real-time vehicle information needs to be saved in a SQL database for later analysis, a simple pass-through query does the job. |
119 | 121 |
|
120 | 122 | Consider the following **input**: |
121 | 123 |
|
@@ -434,7 +436,7 @@ WHERE |
434 | 436 | LAG(Make, 1) OVER (LIMIT DURATION(second, 90)) = Make |
435 | 437 | ``` |
436 | 438 |
|
437 | | -The **LAG** function can look into the input stream one event back and retrieve the *Make* value, comparing that with the *Make* value of the current event. Once the condition is met, data from the previous event can be projected using **LAG** in the **SELECT** statement. |
| 439 | +The **LAG** function can look into the input stream one event back and retrieve the *Make* value, comparing that with the *Make* value of the current event. Once the condition is met, data from the previous event can be projected using **LAG** in the **SELECT** statement. |
438 | 440 |
|
439 | 441 | For more information, see [LAG](/stream-analytics-query/lag-azure-stream-analytics). |
440 | 442 |
|
@@ -851,6 +853,9 @@ For more information on SessionWindow, see [Session Window](/stream-analytics-qu |
851 | 853 |
|
852 | 854 | ## User defined functions in JavaScript and C# |
853 | 855 |
|
| 856 | +> [!NOTE] |
| 857 | +> This section doesn't apply to Fabric Eventstream. |
| 858 | +
|
854 | 859 | Azure Stream Analytics query language can be extended with custom functions written either in JavaScript or C# language. User Defined Functions (UDF) are custom/complex computations that can’t be easily expressed using the **SQL** language. These UDFs can be defined once and used multiple times within a query. For example, an UDF can be used to convert a hexadecimal *nvarchar(max)* value to a *bigint* value. |
855 | 860 |
|
856 | 861 | Sample **input**: |
@@ -945,14 +950,14 @@ MATCH_RECOGNIZE ( |
945 | 950 |
|
946 | 951 | This query matches at least two consecutive failure events and generates an alarm when the conditions are met. |
947 | 952 | **PATTERN** defines the regular expression to be used on the matching, in this case, at least two consecutive warnings after at least one successful operation. |
948 | | -Success and Warning are defined using Return_Code value and once the condition is met, the **MEASURES** are projected with *ATM_id*, the first warning operation and first warning time. |
| 953 | +Success and Warning are defined using Return_Code value and once the condition is met. The MEASURES** are projected with *ATM_id*, the first warning operation, and first warning time. |
949 | 954 |
|
950 | 955 | For more information, see [MATCH_RECOGNIZE](/stream-analytics-query/match-recognize-stream-analytics). |
951 | 956 |
|
952 | 957 | ## Geofencing and geospatial queries |
953 | 958 |
|
954 | 959 | Azure Stream Analytics provides built-in geospatial functions that can be used to implement scenarios such as fleet management, ride sharing, connected cars, and asset tracking. |
955 | | -Geospatial data can be ingested in either GeoJSON or WKT formats as part of event stream or reference data. |
| 960 | +Geospatial data can be ingested in either GeoJSON or WKT formats as part of eventstream or reference data. |
956 | 961 | For example, a company that is specialized in manufacturing machines for printing passports, leases their machines to governments and consulates. The location of those machines is heavily controlled as to avoid the misplacing and possible use for counterfeiting of passports. Each machine is fitted with a GPS tracker, that information is relayed back to an Azure Stream Analytics job. |
957 | 962 | The manufacture would like to keep track of the location of those machines and be alerted if one of them leaves an authorized area, this way they can remotely disable, alert authorities and retrieve the equipment. |
958 | 963 |
|
|
0 commit comments