runtime
77 / 88

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 · keycustomer_idtextnametextgendertextupdated_attext
1 C001 AliceF2025-01-01
2C001Alice NguyenF2025-01-05
3C002Benn/a2025-01-02
4C003CaraF2025-01-03
5C004DevNULL2025-01-04

showing 5 of 6 rows

erp_people3 columns · 5 rows
erp_idtextgendertextbirth_datetext
NASC001Male1990-05-12
NASC002Male1988-02-29
NASC003Female2028-01-01
NASC004Other1995-06-20
NASC999Female1980-01-01

all 5 rows

load_manifest2 columns · 2 rows
source_nametext · keyexpected_rowsinteger
CRM6
ERP5

all 2 rows

example

The idea in one query. Press Run to see what it returns; running examples never affects your progress.

example.sql
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.

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

challenge 1

Return source_name,expected_rows,landed_rows,difference (landed minus expected) for CRM and ERP using load_manifest and the raw tables.

Return source_nameexpected_rowslanded_rowsdifferenceany row order

challenge-1.sql
 
To master this lesson, solve both challenges without hints and pass the concept check. 3 of 3 to go.