`asof_join`
Generic Description
Joins each left event to the latest right event at or before its timestamp. It is documented separately because time construction, sequence ordering, window parameters, and as-of behavior materially change analytical meaning.
Simple example:
WITH [{ts: 1735689600000, value: 10.0, state: 'ok'}, {ts: 1735689660000, value: 13.0, state: 'ok'}, {ts: 1735689840000, value: 9.0, state: 'warn'}, {ts: 1735690200000, value: 16.0, state: 'ok'}] AS readings, [{ts: 1735689300000, state: 'baseline'}, {ts: 1735689720000, state: 'release'}] AS context
RETURN asof_join(readings, context, 900000) AS joined_rows
Consumer-Level Explanation
Use it when context should be historical as-of state, never future state. Prefer this function when the temporal assumption should be visible to the planner, especially for event streams, freshness checks, and sequence features.
More Detailed Explanation
asof_join works on ordered temporal or sequence-style values inside Cypher. The practical contract is to assemble the sequence deliberately, choose the time or window parameter explicitly, and return named fields so downstream planner tooling does not invent unsupported window syntax.
Advanced Example
This example names the event stream and operational context before applying asof_join, which helps planner tooling preserve the intended sequence semantics.
WITH 'sensor-1' AS subject_id,
[{ts: 1735689600000, value: 10.0, state: 'ok'}, {ts: 1735689660000, value: 13.0, state: 'ok'}, {ts: 1735689840000, value: 9.0, state: 'warn'}, {ts: 1735690200000, value: 16.0, state: 'ok'}] AS readings,
[{ts: 1735689300000, state: 'baseline'}, {ts: 1735689720000, state: 'release'}] AS context
RETURN subject_id,
asof_join(readings, context, 900000) AS joined_rows
Real Use Cases
- sessionizing user or device events before feature extraction
- smoothing, rate calculation, or anomaly screening on irregular telemetry
- joining observations to the correct historical context without future leakage
Real Limitations And Tradeoffs
- sequence functions assume the input list is already the intended ordered series
- window size, inactivity threshold, and tolerance values are modeling choices that change results materially
- these helpers are not a replacement for registering temporal properties when the workload needs cataloged timeseries history