Field note · August 5, 2024
Reading region before trusting it in world-indicators
720 rows, 5 distinct values, and the one fact about region that changes how you query it.
Profiling region on world-indicators before anyone builds anything on top of it.
720 rows, no nulls, 5 distinct values. World region.
5 values, and they are not evenly spread: Europe 26.7%, Asia 23.3%, Africa 20.0%, Americas 20.0%. The largest takes 26.7% on its own.
Read the distinct list rather than the distinct count. Casing differences and trailing whitespace produce values that look identical in a report and group separately in SQL, and the count will not show you that — select distinct region order by 1 will, in about a second.
select
count(*) as rows,
count(region) as present,
count(*) - count(region) as nulls,
count(distinct region) as distinct_values
from world_indicators;Low cardinality, stable values — this is a column you can group by without thinking about it, and a reasonable candidate for a chart facet. Check the distinct list, not just the count, because a stray casing variant hides in the count and shows up in the group-by.
Where this bites: a group-by on this column produces 5 rows today. If it is a column an upstream system can add values to, it produces an unknown number tomorrow, and any dashboard laid out for 5 categories reflows without warning. Values arriving is a schema change that no schema check catches.
The grain is one row per country per year, which is the context every one of those numbers depends on. None of them survive a change of grain, which is why "profile the column" and "profile the table" are the same job. Full schema, and the CSV, on the dataset page.