runtime
77 / 88

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 idcustomer_idtextcontact_nametextgendertextupdated_atdate & time
112347Arthur Turnern/a2010-10-31 10:00:00
212347Arthur Turnern/a2010-11-01 10:00:00
312353Harry TurnerM2010-10-27 10:00:00
412359Theo TurnerM2009-12-05 10:00:00
512359Theo TurnerM2010-01-01 10:00:00
612359Theo TurnerM2011-11-01 10:00:00
712373Harry HillM2010-02-04 10:00:00
812373Harry HillM2010-04-01 10:00:00
912373Harry HillM2011-04-01 10:00:00
1012374Emily HillM2010-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 idgendertextbirth_datedate
12389female1978-06-14
12392Female1981-09-17
12416Male2031-05-01
12373Male1962-02-26
12374Male1963-03-27
12817female1983-02-22
12865female1984-02-14
12353NULL1989-06-06
12431female1973-12-28
NAS12447female1989-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 idexpected_rowsnumber
CRM1710
ERP848
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.

  1. 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.sql
    SELECT source_name, expected_rows
    FROM load_manifest;
  2. 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.sql
    SELECT source_row, customer_id, contact_name
    FROM crm_people
    WHERE customer_id IS NULL OR TRIM(customer_id) = '';
  3. 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.sql
    SELECT
      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.

challenge 1

Find the CRM (crm_people) and ERP (erp_people) loads.

Return source_name, expected_rows, landed_rows and difference (landed minus expected).

challenge-1.sql
 
Output
To master this lesson, solve both challenges without hints and pass the concept check. 3 of 3 to go.
Reconcile extraction & Bronze ingestion — Warehouse & reporting projects · Runtime