Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
After each load the pipeline compares row counts between the source database and the warehouse. Small differences are normal — rows written while the snapshot was being taken — and large ones are an incident. Today the check prints both numbers and leaves the judgement to whoever is reading, which means it is ignored.
Write compare_row_counts(source, target, tolerance). Return one row per table.
Function to write
compare_row_counts(source: dict, target: dict, tolerance: float) -> list[dict]One dict per table with table, source, target, delta and status, ordered by table name.
How to approach it
Take the union of the table names first; then each table is one classification.
Sample cases
+ 2 held back until you submit
a nightly reconciliation
An exact match, a small drift inside tolerance, a serious gap, and a table on each side only.
Input
Argument 1
{
'orders': 1000,
'customers': 500,
'events': 2000000,
'legacy_audit': 12
}Argument 2
{
'orders': 1000,
'customers': 497,
'events': 1800000,
'shipments': 80
}Argument 3
0.01Returns
| table | source | target | delta | status |
|---|---|---|---|---|
| customers | 500 | 497 | -3 | within_tolerance |
| events | 2000000 | 1800000 | -200000 | mismatch |
| legacy_audit | 12 | None | None | only_in_source |
| orders | 1000 | 1000 | 0 | match |
| shipments | None | 80 | None | only_in_target |
nothing loaded yet
Two empty systems reconcile to an empty report rather than to an error.
Input
Argument 1
{}Argument 2
{}Argument 3
0.01Returns
[] (empty list)
zero tolerance
With no tolerance allowed, a single missing row is a mismatch.
Input
Argument 1
{
'orders': 1000
}Argument 2
{
'orders': 999
}Argument 3
0Returns
| table | source | target | delta | status |
|---|---|---|---|---|
| orders | 1000 | 999 | -1 | mismatch |
Constraints
table, source, target, delta and status.delta is the target count minus the source count, or None when one side has no count at all.only_in_source or only_in_target. That is an absence, not a count mismatch, and the two need different responses.match.tolerance — measured as a fraction of the source count — is within_tolerance. Anything larger is mismatch.mismatch.Worked example
customers has 500 rows at the source and 497 in the warehouse. Three rows out of five hundred is 0.6 percent, inside a tolerance of 0.01, so it is reported as within tolerance and nobody is paged. events is 2000000 against 1800000 — ten percent, and an incident.
legacy_audit exists only at the source and shipments only in the warehouse. Reporting those as a mismatch with a delta is tempting and wrong: one is a table nobody ever built a pipeline for, the other is a table the source no longer has. Neither is a counting problem, and folding them in with the drift means the two genuine faults are read as four.
What this tests
Classifying differences rather than reporting them, and noticing that absence is a different category from disagreement. The zero-count guard is the one people find in production, when a newly created table divides by nothing.
compare_row_counts(source: dict, target: dict, tolerance: float) -> list[dict]Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.