2 min read
Azure Stream Analytics: Real-Time Data Processing
Azure Stream Analytics processes millions of events per second with SQL-like syntax. No coding required for common streaming patterns.
Basic Query
SELECT
DeviceId,
AVG(Temperature) AS AvgTemp,
MAX(Temperature) AS MaxTemp,
System.Timestamp() AS WindowEnd
FROM IoTInput TIMESTAMP BY EventTime
GROUP BY
DeviceId,
TumblingWindow(minute, 5)
Window Types
Tumbling Window
Fixed, non-overlapping intervals:
TumblingWindow(minute, 5)
-- |---5min---|---5min---|---5min---|
Hopping Window
Fixed intervals that overlap:
HoppingWindow(minute, 10, 5)
-- 10-minute windows every 5 minutes
Sliding Window
Window slides with each event:
SlidingWindow(minute, 5)
-- Triggers on every event, includes last 5 minutes
Session Window
Groups events with gaps:
SessionWindow(minute, 5, 30)
-- 5-minute timeout, 30-minute max duration
Anomaly Detection
SELECT
DeviceId,
Temperature,
AnomalyDetection_SpikeAndDip(Temperature, 95, 120, 'spikesanddips') AS SpikeAndDip
FROM IoTInput
Reference Data Join
SELECT
i.DeviceId,
d.DeviceName,
d.Location,
i.Temperature
FROM IoTInput i TIMESTAMP BY EventTime
JOIN DeviceReference d ON i.DeviceId = d.DeviceId
Output to Multiple Sinks
-- To Power BI for dashboards
SELECT * INTO PowerBIOutput FROM AggregatedData
-- To Blob for archival
SELECT * INTO BlobOutput FROM RawData
-- To Event Hub for downstream processing
SELECT * INTO EventHubOutput WHERE IsAnomaly = 1
Stream Analytics bridges the gap between raw event streams and actionable insights.