Data Cleaning Exercises

Task: the rules
Input
  events(id, raw_date, locale) — text. id is unique. locale may be missing.

Rules
  Accept raw_date when it is:
    - an ISO date YYYY-MM-DD (any locale, including missing), or
    - a slash date D/M/YYYY or M/D/YYYY (1–2 digit day and month) AND locale is
        en-US → month first, or en-GB → day first.
  Quarantine with reason:
    invalid_date      raw_date is missing, or a slash date with a declared locale names a day that does not exist (31/02/2026)
    ambiguous_format  anything else, including a slash date whose locale is missing or not en-US/en-GB

Outputs (row order does not matter)
  clean(id text, date date)
  exceptions(id text, reason text)

Tab inserts spaces. Press Escape, then Tab, to move focus out of the editor.

Input: events, rows 1 to 8 of 8
#idstringraw_datestringlocalestring
1evvsoj04/08/2025en-GB
2evkcwt02/12/2025en-GB
3evsig02025-06-05en-US
4evrwhn6/20/2025missing
5evsr7005/12/2025en-GB
6eva3552026/04/03en-GB
7evnf0z13/13/2026en-GB
8eve73401/03/2026en-US

Run preview · in your browser, not a grade

Loading the preview runtime…

Check answer · graded on an isolated server, including hidden datasets

Your code runs in a locked-down machine with no network, on the visible data and on hidden datasets that follow the same rules.

Learn from this exercise

A worked solution becomes available after your first check or once you've used every hint.

AI tutor · may be wrong; the grader decides

SQL · DuckDB 1.5.1Preview runtime loadingNot saved yet · sign in to save to your account