Combining two datasets is rarely a matter of aligning column names. The difficult work is deciding whether two fields mean the same thing, whether two records describe the same entity, which source wins when values disagree, and how a consumer can trace the result.
Four layers of integration
| Layer | Question | Example failure |
|---|---|---|
| Syntax | Can the bytes be parsed? | A quoted CSV field contains a newline |
| Schema | Which fields correspond? | venue means a name in one source and an ID in another |
| Entity | Which records refer to the same thing? | MIT and Massachusetts Institute of Technology split |
| Semantics | Which value is valid in this context? | Two systems use different definitions of “active” |
Passing the first layer does not prove the data is integrated. A pipeline can parse perfectly while silently merging different concepts.
In plain terms: formatting asks whether two labels can fit in the same box. Semantics asks whether they should be in the same box at all.
Warehouse or federation
A warehouse copies and transforms source data into a controlled target. It supports stable performance, history, and governance, but introduces ingestion delay and duplicated state.
A federated query leaves data at each source and combines it at query time. It can be fresher and avoids a full copy, but performance and correctness depend on source availability, latency, and query capability.
| Need | Prefer materialization | Prefer federation |
|---|---|---|
| Repeatable analytics and history | ✓ | |
| Strictly current source value | ✓ | |
| Predictable query latency | ✓ | |
| Data cannot be copied | ✓ | |
| Source has limited filtering or joins | ✓ |
Many systems use both: materialize stable analytical facts, then federate a narrow live lookup.
Schema mapping needs explicit rules
For every target field, record:
- source field and source system;
- transformation and units;
- null and invalid-value policy;
- authoritative source or precedence rule;
- effective time and refresh cadence;
- owner and downstream consumers.
This turns a collection of scripts into a data contract. When a source changes price from dollars to cents, the failure becomes detectable rather than mysterious.
Entity resolution is a decision process
Exact string equality is too strict, while fuzzy matching alone is too eager. A safer flow is:
- Normalize: case, punctuation, whitespace, Unicode, known abbreviations.
- Block: generate plausible candidate pairs using a cheap key.
- Compare: score multiple attributes such as name, email, address, or date.
- Decide: match, non-match, or manual review.
- Merge: apply field-level survivorship rules.
- Preserve lineage: retain source IDs, original values, rule version, and confidence.
For a research database, author name alone is weak evidence. Email, affiliation, coauthors, and publication history can help, but every signal has failure cases. A merged identity should be reversible.
Provenance is part of the data
A trustworthy derived record should answer:
- Which source records produced it?
- Which transformation version ran?
- When was the source observed?
- Which rule chose the surviving value?
- Can the output be rebuilt exactly?
Without provenance, a wrong value becomes a debate. With provenance, it becomes a traceable defect.
Test the pipeline at boundaries
Row count alone is a weak test. Add checks for uniqueness, referential integrity, null distribution, accepted ranges, freshness, and rejected records. Include fixtures with embedded delimiters, quoted newlines, duplicate identities, late arrivals, deleted source records, and unit changes.
-- Orphan check after loading a paper-author relationship.
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;
The result should be empty, but the rejected-input table should not be. Quietly dropping malformed records makes a clean dashboard by hiding the problem.
Review card
- Integration spans syntax, schema, identity, and semantics.
- Warehousing copies data; federation integrates at query time.
- Field mappings need units, null policy, precedence, and ownership.
- Entity resolution needs candidate generation, evidence, thresholds, and reversible merges.
- Provenance makes derived facts explainable and rebuildable.
- Test rejected and edge-case data, not only successful row counts.
合併兩份 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。