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

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 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
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 idgendertextbirth_datedate
12389female1978-06-14
12392Female1981-09-17
12416Male2031-05-01
12373Male1962-02-26
12374Male1963-03-27
12817female1983-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 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

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.

  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

Return source_name, expected_rows, landed_rows and difference (landed minus expected) for the CRM (crm_people) and ERP (erp_people) loads.

what to return

Columns
source_nameexpected_rowslanded_rowsdifference in this order
Rows
any order
challenge-1.sql
 
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