时间连接
模式。 用事件发生时生效的维度版本补全每个事件。ArkFlow 的 sql
processor 把批次与 temporary source 连接;时间范围谓词完成时间选择。
配置
维度表放在 Redis(由上游 Job 写入,例如
SCD-2 查询);SQL
连接选出每个订单 ts 时生效的 tier:
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
key(expr: user)限定 temporary source 每行加载的内容;JOIN条件随后 施加时间范围。next_effective_ts IS NULL让最新版本无限期生效。
输入与输出
批次输入:
| order_id | user | ts |
|---|---|---|
| o-1 | a | 1500 |
维度(tiers,来自 SCD-2):
| user | tier | effective_ts | next_effective_ts |
|---|---|---|---|
| a | silver | 1000 | 2000 |
| a | gold | 2000 | NULL |
输出:
| order_id | user | ts | tier |
|---|---|---|---|
| o-1 | a | 1500 | gold |
可运行示例
examples/sql_temporal_join.yaml
(manifest 名称 sql-temporal-join)。它需要一个存有维度行的可达 Redis;
装载方式见 redis temporary 组件。
边界
- 两条流按事件时间区间连接是 Job DAG 的 键控区间连接——两侧都是流时请用它。
- temporary source 每批次重新读取;大而快变的维度应放入 SQL 可达的正式表 sink,或使用连接算子。