lesson 77 Warehouse & reporting projects · advanced
Reconcile extraction & Bronze ingestion
Reconcile source counts with ingested records.
the idea
Bronze preserves raw values. Compare a supplied extraction manifest to landed counts before cleaning; a matching count alone cannot prove correct column alignment. A discrepancy is evidence to investigate, not permission to delete data.
tables in this lesson
The challenges use this data. Each column shows its type underneath; → marks a link to another table.
crm_people5 columns · 6 rows
| source_rowinteger · key | customer_idtext | nametext | gendertext | updated_attext |
|---|---|---|---|---|
| 1 | C001 | Alice | F | 2025-01-01 |
| 2 | C001 | Alice Nguyen | F | 2025-01-05 |
| 3 | C002 | Ben | n/a | 2025-01-02 |
| 4 | C003 | Cara | F | 2025-01-03 |
| 5 | C004 | Dev | NULL | 2025-01-04 |
showing 5 of 6 rows
erp_people3 columns · 5 rows
| erp_idtext | gendertext | birth_datetext |
|---|---|---|
| NASC001 | Male | 1990-05-12 |
| NASC002 | Male | 1988-02-29 |
| NASC003 | Female | 2028-01-01 |
| NASC004 | Other | 1995-06-20 |
| NASC999 | Female | 1980-01-01 |
all 5 rows
load_manifest2 columns · 2 rows
| source_nametext · key | expected_rowsinteger |
|---|---|
| CRM | 6 |
| ERP | 5 |
all 2 rows
example
The idea in one query. Press Run to see what it returns; running examples never affects your progress.
WITH landed AS( SELECT 'CRM' AS source_name,COUNT(*) AS landed_rows FROM crm_people UNION ALL SELECT 'ERP',COUNT(*) FROM erp_people ) SELECT m.source_name, m.expected_rows, l.landed_rows, l.landed_rows-m.expected_rows AS difference FROM load_manifest m JOIN landed l USING(source_name);
Watch for: Counts cannot detect shifted CSV columns. BULK INSERT and file paths are T-SQL reference concepts; these are preloaded synthetic extracts.
build it step by step
Each step changes one thing. Run them in order and watch the result change.
Understand the source contract. Fictional extracts, load counts, invalid dates, versioned dimensions, refresh staging and a data catalog. The foundation project is latest-state; separate history and incremental labs demonstrate extensions.
step-1.sqlSELECT * FROM load_manifest;
Execute the transformation. Bronze preserves raw values. Compare a supplied extraction manifest to landed counts before cleaning; a matching count alone cannot prove correct column alignment. A discrepancy is evidence to investigate, not permission to delete data.
step-2.sqlWITH landed AS( SELECT 'CRM' AS source_name,COUNT(*) AS landed_rows FROM crm_people UNION ALL SELECT 'ERP',COUNT(*) FROM erp_people ) SELECT m.source_name, m.expected_rows, l.landed_rows, l.landed_rows-m.expected_rows AS difference FROM load_manifest m JOIN landed l USING(source_name);
Test another question. Counts cannot detect shifted CSV columns. BULK INSERT and file paths are T-SQL reference concepts; these are preloaded synthetic extracts.
step-3.sqlSELECT source_row,customer_id FROM crm_people WHERE customer_id IS NULL OR TRIM(customer_id)=''