Testing transformation rules
ETL & Data Warehouse Testing · 7 questions
Short notes
Key idea
For every mapping rule: compute the expected value from the source using the rule's own words, compare with the actual target value, and return the rows that differ. No rows means pass. Write expected values independently of the developer's code.
Syntax
SELECT order_key, status, status_group
FROM dw_orders
WHERE status_group IS DISTINCT FROM CASE
WHEN status IN ('delivered','shipped') THEN 'fulfilled'
WHEN status = 'pending' THEN 'open'
WHEN status IN ('cancelled','returned') THEN 'lost' END;
-- Crosstab: each input should map to one output
SELECT status, status_group, COUNT(*) FROM dw_orders GROUP BY 1, 2;
Defaults: compare with COALESCE(source, 'Unknown') using IS DISTINCT FROM.
Example
Shop: returned orders 47 (twice), 52 and 58 mapped to fulfilled; order 56's NULL payment method not turned into Unknown. Both only in 2024 incremental runs, so they likely share one root cause.
Traps
- Copying the developer's SQL as the expected value.
<>on nullable values hides failures.- Forgetting source values the mapping doesn't list.
- Skipping rounding, case, length and time-zone edges.
Want the full lesson with step-by-step examples, a project and a certificate? ETL & Data Warehouse Testing course, ₹120 →
- Question 1easy
How many rows break the order_month rule?
SELECT COUNT(*) FROM dw_orders WHERE order_month IS DISTINCT FROM strftime(order_date, '%Y-%m');
- Question 2medium
What does this return?
SELECT COUNT(*) FROM dw_orders WHERE status = 'returned' AND status_group = 'fulfilled';
- Question 3medium
The source starts sending a new status,
on_hold. The load's CASE has no ELSE. What happens, and which check catches it? - Question 4easy
Why write the expected CASE yourself instead of copying the developer's transformation SQL?
- Question 5hard
A rule says amounts are rounded to 2 decimals. Which test value is most likely to expose a rounding bug?
Testing transformation rules
Testing transformation rules
Testing transformation rules
Testing transformation rules
Testing transformation rules
2 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.