Temporal join
Pattern. Enrich each event with the dimension version that was effective at
the event's time. ArkFlow's sql processor joins the batch against a
temporary source; the time-range predicate does the temporal selection.
The configuration
The dimension table lives in Redis (populated by an upstream job, e.g. the
SCD-2 query); the SQL join
selects the tier effective at each order's ts:
temporary:
- name: user_tiers
type: redis
mode:
type: single
url: redis://127.0.0.1:6379
redis_type:
type: string
codec:
type: json
pipeline:
processors:
- type: sql
query: |
SELECT o.order_id, o.user, o.ts, t.tier
FROM flow o
JOIN tiers t
ON o.user = t.user
AND o.ts >= t.effective_ts
AND (t.next_effective_ts IS NULL OR o.ts < t.next_effective_ts)
table_name: flow
temporary_list:
- name: user_tiers
table_name: tiers
key:
type: expr
expr: user
- The
key(expr: user) narrows what the temporary source loads per row; theJOINcondition then applies the temporal range. next_effective_ts IS NULLkeeps the newest version open-ended.
Input and output
Batch input:
| order_id | user | ts |
|---|---|---|
| o-1 | a | 1500 |
Dimension (tiers, from SCD-2):
| user | tier | effective_ts | next_effective_ts |
|---|---|---|---|
| a | silver | 1000 | 2000 |
| a | gold | 2000 | NULL |
Output:
| order_id | user | ts | tier |
|---|---|---|---|
| o-1 | a | 1500 | gold |
Runnable example
examples/sql_temporal_join.yaml
(manifest name sql-temporal-join). It needs a reachable Redis holding the
dimension rows; see the
redis temporary component for loading.
Boundaries
- Streaming temporal joins with event time (two streams joined by interval) are the Job DAG's keyed interval join — use that when both sides are streams.
- The temporary source is re-read per batch; a large, fast-changing dimension belongs in a proper table sink the SQL can reach, or in the join operator.