lesson 77 Warehouse & reporting projects · advanced
Reconcile extraction & Bronze ingestion
Reconcile source counts with ingested records.
the idea
Before cleaning, reconcile what landed with what the source said it sent. Compare a load manifest’s expected row counts with the rows that arrived, and list records that cannot be keyed. A difference is evidence to investigate with the source owner, not permission to delete data.
Dataset: Retail
crm_people5 columns · 1,707 rows
| source_rownumber · unique id | customer_idtext | contact_nametext | gendertext | updated_atdate & time |
|---|---|---|---|---|
| 1 | 12347 | Arthur Turner | n/a | 2010-10-31 10:00:00 |
| 2 | 12347 | Arthur Turner | n/a | 2010-11-01 10:00:00 |
| 3 | 12353 | Harry Turner | M | 2010-10-27 10:00:00 |
| 4 | 12359 | Theo Turner | M | 2009-12-05 10:00:00 |
| 5 | 12359 | Theo Turner | M | 2010-01-01 10:00:00 |
| 6 | 12359 | Theo Turner | M | 2011-11-01 10:00:00 |
| 7 | 12373 | Harry Hill | M | 2010-02-04 10:00:00 |
| 8 | 12373 | Harry Hill | M | 2010-04-01 10:00:00 |
| 9 | 12373 | Harry Hill | M | 2011-04-01 10:00:00 |
| 10 | 12374 | Emily Hill | M | 2010-04-30 10:00:00 |
- source_rownumber · unique id
- 1
- customer_idtext
- 12347
- contact_nametext
- Arthur Turner
- gendertext
- n/a
- updated_atdate & time
- 2010-10-31 10:00:00
- source_rownumber · unique id
- 2
- customer_idtext
- 12347
- contact_nametext
- Arthur Turner
- gendertext
- n/a
- updated_atdate & time
- 2010-11-01 10:00:00
- source_rownumber · unique id
- 3
- customer_idtext
- 12353
- contact_nametext
- Harry Turner
- gendertext
- M
- updated_atdate & time
- 2010-10-27 10:00:00
- source_rownumber · unique id
- 4
- customer_idtext
- 12359
- contact_nametext
- Theo Turner
- gendertext
- M
- updated_atdate & time
- 2009-12-05 10:00:00
- source_rownumber · unique id
- 5
- customer_idtext
- 12359
- contact_nametext
- Theo Turner
- gendertext
- M
- updated_atdate & time
- 2010-01-01 10:00:00
- source_rownumber · unique id
- 6
- customer_idtext
- 12359
- contact_nametext
- Theo Turner
- gendertext
- M
- updated_atdate & time
- 2011-11-01 10:00:00
- source_rownumber · unique id
- 7
- customer_idtext
- 12373
- contact_nametext
- Harry Hill
- gendertext
- M
- updated_atdate & time
- 2010-02-04 10:00:00
- source_rownumber · unique id
- 8
- customer_idtext
- 12373
- contact_nametext
- Harry Hill
- gendertext
- M
- updated_atdate & time
- 2010-04-01 10:00:00
- source_rownumber · unique id
- 9
- customer_idtext
- 12373
- contact_nametext
- Harry Hill
- gendertext
- M
- updated_atdate & time
- 2011-04-01 10:00:00
- source_rownumber · unique id
- 10
- customer_idtext
- 12374
- contact_nametext
- Emily Hill
- gendertext
- M
- updated_atdate & time
- 2010-04-30 10:00:00
first 10 of 1,707 rows · your queries use all of them
erp_people3 columns · 848 rows
| erp_idtext · unique id | gendertext | birth_datedate |
|---|---|---|
| 12389 | female | 1978-06-14 |
| 12392 | Female | 1981-09-17 |
| 12416 | Male | 2031-05-01 |
| 12373 | Male | 1962-02-26 |
| 12374 | Male | 1963-03-27 |
| 12817 | female | 1983-02-22 |
| 12865 | female | 1984-02-14 |
| 12353 | NULL | 1989-06-06 |
| 12431 | female | 1973-12-28 |
| NAS12447 | female | 1989-04-16 |
- erp_idtext · unique id
- 12389
- gendertext
- female
- birth_datedate
- 1978-06-14
- erp_idtext · unique id
- 12392
- gendertext
- Female
- birth_datedate
- 1981-09-17
- erp_idtext · unique id
- 12416
- gendertext
- Male
- birth_datedate
- 2031-05-01
- erp_idtext · unique id
- 12373
- gendertext
- Male
- birth_datedate
- 1962-02-26
- erp_idtext · unique id
- 12374
- gendertext
- Male
- birth_datedate
- 1963-03-27
- erp_idtext · unique id
- 12817
- gendertext
- female
- birth_datedate
- 1983-02-22
- erp_idtext · unique id
- 12865
- gendertext
- female
- birth_datedate
- 1984-02-14
- erp_idtext · unique id
- 12353
- gendertext
- NULL
- birth_datedate
- 1989-06-06
- erp_idtext · unique id
- 12431
- gendertext
- female
- birth_datedate
- 1973-12-28
- erp_idtext · unique id
- NAS12447
- gendertext
- female
- birth_datedate
- 1989-04-16
first 10 of 848 rows · your queries use all of them
load_manifest2 columns · 2 rows
| source_nametext · unique id | expected_rowsnumber |
|---|---|
| CRM | 1710 |
| ERP | 848 |
- source_nametext · unique id
- CRM
- expected_rowsnumber
- 1710
- source_nametext · unique id
- ERP
- expected_rowsnumber
- 848
all 2 rows
worked example
The step marked “the pattern” is what the challenges build on. Running examples doesn’t count toward progress.
Read expected row counts. load_manifest records what CRM and ERP said they sent—reconciliation starts by comparing these expectations to what landed.the pattern
example.sqlSELECT source_name, expected_rows FROM load_manifest;
Find CRM rows without a key. Run this. Missing or blank customer_id rows cannot join to a customer master until you fix or quarantine them.
step-2.sqlSELECT source_row, customer_id, contact_name FROM crm_people WHERE customer_id IS NULL OR TRIM(customer_id) = '';
Compare row count to distinct keys. When crm_rows exceeds distinct_keys, the same customer id arrived more than once—you will dedupe in integration.
step-3.sqlSELECT COUNT(*) AS crm_rows, COUNT(DISTINCT TRIM(customer_id)) AS distinct_keys FROM crm_people;
common mistake
Matching counts do not prove the load is right: shifted columns or swapped values keep the same number of rows.