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
The tables the challenges use, with their first 6 rows. Under each column name: the kind of value it holds, and which table it links to.
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 |
- 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
first 6 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 |
- 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
first 6 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
Run these steps in order to see the idea before you write your own query. The step marked “the pattern” is what the challenges ask for. Running the example does not 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.