合併兩份 dataset 很少只是把 column name 對齊。真正困難的是:兩個 field 是否代表同一概念、兩筆 record 是否是同一個 entity、來源衝突時相信誰,以及 consumer 能否追查最後結果從哪裡來。
Integration 的四個層次
| 層次 | 問題 | 失敗例子 |
|---|---|---|
| Syntax | Bytes 能不能 parse? | Quoted CSV field 裡有 newline |
| Schema | 哪些 field 對應? | 一邊的 venue 是名稱,另一邊是 ID |
| Entity | 哪些 record 指同一個東西? | MIT 與完整校名被拆成兩個機構 |
| Semantics | 這個情境下哪個值才有效? | 兩個系統對「active」定義不同 |
通過第一層不代表資料已經整合。Pipeline 可以 parse 得完全正確,卻安靜地把不同概念混在一起。
白話來說: Format 問兩張標籤能不能塞進同一格;semantics 問它們到底該不該放進同一格。
Warehouse 或 federation
Warehouse 把 source data copy 並 transform 到受控 target。它提供穩定效能、歷史與治理,但會有 ingestion delay 和 duplicated state。
Federated query 讓資料留在各 source,query 時再組合。資料可以更即時,也不用完整複製;但 performance 與 correctness 受 source availability、latency 與 query capability 限制。
| 需求 | Materialization 較適合 | Federation 較適合 |
|---|---|---|
| 可重現 analytics 與 history | ✓ | |
| 必須讀到 source 最新值 | ✓ | |
| 可預測 query latency | ✓ | |
| 資料不能被複製 | ✓ | |
| Source filter/join 能力有限 | ✓ |
實務上常混用:穩定的 analytical fact 先 materialize,少量即時 lookup 再 federate。
Schema mapping 必須寫成規則
每個 target field 應記錄:
- source system 與 source field;
- transformation 與 unit;
- null、invalid-value policy;
- authoritative source 或 precedence rule;
- effective time 與 refresh cadence;
- owner 與 downstream consumer。
這會把零散 script 變成 data contract。若 source 將 price 從 dollar 改成 cent,系統能明確偵測,而不是幾週後才發現數字怪異。
Entity resolution 是決策流程
Exact string equality 太嚴格,只用 fuzzy matching 又太積極。較安全的流程是:
- Normalize: case、punctuation、whitespace、Unicode、已知 abbreviation。
- Block: 用便宜的 key 產生合理 candidate pair。
- Compare: 綜合 name、email、address、date 等 attribute 評分。
- Decide: match、non-match 或 manual review。
- Merge: 套 field-level survivorship rule。
- Preserve lineage: 保留 source ID、original value、rule version 與 confidence。
以研究資料為例,只靠 author name 證據太弱。Email、affiliation、coauthor 和 publication history 都能補強,但每個 signal 都有反例;合併後的 identity 應能被拆回去。
Provenance 本身就是資料
可信的 derived record 應回答:
- 哪些 source record 產生它?
- 哪個 transformation version 執行?
- 何時觀察到 source?
- 哪條 rule 選了最後值?
- 能不能完全重建 output?
沒有 provenance,錯誤值會變成爭論;有 provenance,它只是可追查的 defect。
在 boundary 測 pipeline
只檢查 row count 很弱。還要驗 uniqueness、referential integrity、null distribution、accepted range、freshness 與 rejected record。Fixture 應包含 embedded delimiter、quoted newline、duplicate identity、late arrival、source deletion 與 unit change。
-- 載入 paper-author relationship 後檢查 orphan。
SELECT pa.paper_id
FROM paper_author AS pa
LEFT JOIN paper AS p ON p.id = pa.paper_id
WHERE p.id IS NULL;
結果應該為空,但 rejected-input table 不應永遠是空的。把 malformed record 安靜丟掉,只是用隱藏問題換來乾淨 dashboard。
複習卡
- Integration 橫跨 syntax、schema、identity 與 semantics。
- Warehouse 複製資料;federation 在 query time 整合。
- Field mapping 需要 unit、null policy、precedence 與 ownership。
- Entity resolution 需要 candidate、evidence、threshold 與可逆 merge。
- Provenance 讓 derived fact 能解釋、能重建。
- 除了成功 row count,也要測 rejected 與 edge-case data。