Streaming queries
Experimental snapshot, replay, window, and emission semantics.
Status: Experimental
Streaming is a statement prefix:
STREAM SELECT id, market, amount
FROM trades
WHERE amount > 1000;The server emits an initial result snapshot and then keeps the request open for committed changes that can affect the result.
Streaming is always a statement prefix: use STREAM SELECT .... A
disconnected subscription is terminal; the current release does not
promise a durable resume token or cross-connection replay position.
Historical replay and follow
HISTORICAL SELECT is a one-shot attribute-history read. Place STREAM
outside HISTORICAL to replay that attribute stream and then follow new
changes. V1 requires an attribute table and exactly one declared attribute,
plus its entity and axis columns. The example uses the one-attribute table from
the SELECT reference:
HISTORICAL SELECT instrument_id, observed_at, price
FROM instrument_prices;
STREAM HISTORICAL SELECT instrument_id, observed_at, price
FROM instrument_prices;The streaming historical form is append-preserving and rejects ORDER BY,
DISTINCT, LIMIT, and multi-attribute projections. The available replay range
follows table retention and storage state. It is not a broker retention SLA and
is not a backup.
Windows
Window relation functions add window_start and window_end fields.
Tumbling
STREAM SELECT market, window_start, window_end, sum(amount) AS volume
FROM tumble(trades, observed_at, INTERVAL 1 MINUTE)
GROUP BY market, window_start, window_end
EMIT AFTER WINDOW CLOSE;Hopping
STREAM SELECT market, window_start, sum(amount) AS volume
FROM hop(
trades,
observed_at,
INTERVAL 5 MINUTE,
INTERVAL 1 MINUTE
)
GROUP BY market, window_start
EMIT PERIODIC INTERVAL 1 SECOND;The third argument is window size and the fourth is slide.
Session
STREAM SELECT account_id, window_start, window_end, count() AS events
FROM session(
account_events,
observed_at,
INTERVAL 30 SECOND,
INTERVAL 5 MINUTE
)
GROUP BY account_id, window_start, window_end
EMIT AFTER WINDOW CLOSE;The idle gap is required; maximum duration is optional. Session windows support
EMIT AFTER WINDOW CLOSE only.
Emission policies
| Policy | Use |
|---|---|
EMIT AFTER WINDOW CLOSE | Emit a window result at close. The projection must include window_start or window_end. |
... WITH DELAY INTERVAL ... AND TIMEOUT INTERVAL ... | Add allowed delay and an optional timeout to window-close emission. |
EMIT PERIODIC INTERVAL ... | Emit on a cadence. REPEAT re-emits aggregate state. |
EMIT CHANGELOG ON UPDATE | Emit aggregate changes as retractions and additions. |
... WITH BATCH INTERVAL ... | Batch changelog updates. |
EMIT PER EVENT | Emit for each accepted source event. |
EMIT CHANGELOG requires a retractable result shape: an aggregate, an explicit
changelog source, or a supported join.
REPEAT requires aggregate state.
Bound aggregate state
Set a positive idle-state TTL on a streaming aggregate:
STREAM SELECT market, sum(amount) AS volume
FROM trades
GROUP BY market
EMIT CHANGELOG ON UPDATE
SETTINGS state_ttl = '1h';Accepted duration suffixes include ms, s, m, h, and d.
state_ttl applies only to aggregate state; the binder rejects it on one-shot
or non-aggregate reads.
Lifecycle and delivery
A subscription ends on client cancellation, connection failure, server shutdown, source drop, or a terminal engine error. A source drop is surfaced as a terminal condition instead of leaving a cursor attached to a new object with the same name.
Clients should:
- treat every stream as unbounded;
- apply read deadlines and downstream backpressure;
- monitor
system.subscriptionsand stream-related events; - make sinks idempotent where replay is possible; and
- open a new subscription under an explicit retry policy after termination.
See Streaming reads for channel sharing and continuity boundaries.