Windows
Windows are fundamental to stream processing, allowing you to group events for aggregation and analysis. EventFlux supports 14 window types to cover different streaming scenarios.
Window Syntax
SELECT ...
FROM StreamName
WINDOW('windowType', parameters)
GROUP BY column
INSERT INTO Output;
Time Units: Windows use readable time units: MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS, WEEKS
Window Types Overview
| Window | Type | Description | Use Case |
|---|---|---|---|
| Tumbling | Time | Fixed, non-overlapping | Hourly/daily reports |
| Sliding | Time | Overlapping with slide | Moving averages |
| Session | Time | Gap-based | User sessions |
| Time | Time | Continuous rolling | Real-time monitoring |
| TimeBatch | Time | Periodic batches | Scheduled snapshots |
| ExternalTime | Time | Event timestamp | Out-of-order events |
| Length | Count | Last N events | Recent history |
| LengthBatch | Count | N-event batches | Batch processing |
| Delay | Time | Delayed emission | Late arrival handling |
| Unique | Key | Latest per unique key | Deduplication (keep latest) |
| FirstUnique | Key | First per unique key | Deduplication (keep first) |
| Expression | Count | Expression-based size | Dynamic count limits |
| Frequent | Statistical | Most frequent events | Top-N analysis |
| LossyFrequent | Statistical | Approximate frequency | High-volume frequency estimation |
Time-Based Windows
Tumbling Window
Non-overlapping, fixed-size time windows. Events are assigned to exactly one window.
-- 5-minute tumbling windows
SELECT sensor_id,
AVG(temperature) AS avg_temp,
COUNT(*) AS reading_count
FROM SensorReadings
WINDOW('tumbling', 5 MINUTES)
GROUP BY sensor_id
INSERT INTO FiveMinuteStats;
Visual Representation:
Events: ──●──●──●──●──●──●──●──●──●──●──●──●──●──▶
Windows: [────────][────────][────────][────────]
W1 W2 W3 W4
Sliding Window
Overlapping windows with configurable slide interval.
-- 10-second window, sliding every 2 seconds
SELECT symbol,
AVG(price) AS moving_avg,
MAX(price) AS max_price
FROM StockTrades
WINDOW('sliding', 10 SECONDS, 2 SECONDS)
GROUP BY symbol
INSERT INTO MovingAverages;
Parameters:
- First: Window size (with time unit)
- Second: Slide interval (with time unit)
Visual Representation:
Events: ──●──●──●──●──●──●──●──●──▶
Windows: [────────────]
[────────────]
[────────────]
[────────────]
Session Window
Groups events with gaps shorter than the timeout. Sessions end after inactivity.
-- User sessions with 30-minute timeout
SELECT user_id,
COUNT(*) AS click_count,
MIN(timestamp) AS session_start,
MAX(timestamp) AS session_end
FROM ClickStream
WINDOW('session', 30 MINUTES)
GROUP BY user_id
INSERT INTO UserSessions;
Use Cases:
- User activity sessions
- Device connectivity windows
- Transaction sequences
Visual Representation:
Events: ●●●● ●● ●●●●●●● ●●●●
Sessions: [──────] [─] [─────────] [────]
Session1 S2 Session3 S4
Time Window
Continuous rolling window based on event time.
-- Rolling 1-minute window
SELECT sensor_id,
AVG(value) AS rolling_avg
FROM Readings
WINDOW('time', 1 MINUTE)
GROUP BY sensor_id
INSERT INTO RollingStats;
TimeBatch Window
Batches events and emits at fixed intervals.
-- Emit batch every 10 seconds
SELECT symbol,
SUM(volume) AS total_volume,
COUNT(*) AS trade_count
FROM Trades
WINDOW('timeBatch', 10 SECONDS)
GROUP BY symbol
INSERT INTO BatchedStats;
ExternalTime Window
Uses a timestamp attribute from the event for windowing (event time vs processing time).
-- Use event timestamp for windowing
SELECT device_id,
AVG(temperature) AS avg_temp
FROM SensorData
WINDOW('externalTime', event_time, 5 MINUTES)
GROUP BY device_id
INSERT INTO Stats;
Parameters:
- First: Timestamp attribute name
- Second: Window duration (with time unit)
Count-Based Windows
Length Window
Maintains a sliding window of the last N events.
-- Keep last 100 trades per symbol
SELECT symbol,
AVG(price) AS avg_price,
STDDEV(price) AS price_stddev
FROM StockTrades
WINDOW('length', 100)
GROUP BY symbol
INSERT INTO RecentStats;
Visual Representation:
Events: 1 2 3 4 5 6 7 8 9 ...
Window: [3 4 5 6 7] (length=5)
[4 5 6 7 8]
[5 6 7 8 9]