lesson 71 Warehouse & reporting projects · advanced
Bronze: inspect raw data before cleaning
Inspect incoming records before making cleaning decisions.
the idea
Bronze preserves source records for traceability. Profile missing keys, duplicates, dates, and type mismatches before writing cleaning rules. Do not silently erase rows without documenting why. These source rows are fictional, inspired by common CRM/catalog/sales issues.
tables in this lesson
The challenges use this data. Each column shows its type underneath; → marks a link to another table.
bronze_customers4 columns · 7 rows
| raw_idtext | nametext | countrytext | updated_attext |
|---|---|---|---|
| C001 | Alice | USA | 2025-01-01 |
| C001 | Alice Nguyen | US | 2025-01-05 |
| C002 | Ben | GB | 2025-01-02 |
| C003 | Cara | UK | 2025-01-03 |
| C004 | Dev | IND | 2025-01-04 |
showing 5 of 7 rows
bronze_sales6 columns · 13 rows
| row_idinteger · key | customer_idtext | product_idtext | quantitytext | salestext | order_datetext |
|---|---|---|---|---|---|
| 1 | C001 | P01 | 2 | 24 | 2025-01-01 |
| 2 | C002 | P03 | 1 | 80 | 2025-01-02 |
| 3 | C001 | P02 | 1 | 45 | 2025-01-15 |
| 4 | C003 | P04 | 2 | 240 | 2025-02-01 |
| 5 | C004 | P03 | 2 | 160 | 2025-02-05 |
showing 5 of 13 rows
example
The idea in one query. Press Run to see what it returns; running examples never affects your progress.
SELECT TRIM(raw_id) AS customer_id,COUNT(*) AS versions FROM bronze_customers WHERE raw_id IS NOT NULL GROUP BY TRIM(raw_id) HAVING COUNT(*)>1;
Watch for: A date parse check is not a complete calendar validation policy; production rules must also define format and acceptable ranges.
build it step by step
Each step changes one thing. Run them in order and watch the result change.
Preserve the raw input. Note duplicate C001, spaces, and the missing key.
step-1.sqlSELECT * FROM bronze_customers;
Profile duplicates. Normalize keys for analysis without modifying the Bronze table.
step-2.sqlSELECT TRIM(raw_id) AS customer_id,COUNT(*) AS versions FROM bronze_customers WHERE raw_id IS NOT NULL GROUP BY TRIM(raw_id) HAVING COUNT(*)>1
Inspect rejected dates. The invalid source row remains traceable.
step-3.sqlSELECT row_id,order_date FROM bronze_sales WHERE date(order_date) IS NULL