Data Cleaning Exercises

Task: the rules
Input
  tickets(id, channel) — text. id is unique. channel may be missing.

Rules
  channel: remove ASCII whitespace (space, tab, CR, LF) at both ends, then lowercase; an empty result is missing.
  Map channel with this approved dictionary (left → right) and nothing else:
    email → email      e-mail → email
    phone → phone      telephone → phone
    chat → chat        web chat → chat      webchat → chat
  Quarantine to exceptions with reason:
    missing_channel    channel is missing
    unmapped_channel   channel is present but not in the dictionary (never guess a mapping)

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

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

Input: tickets, rows 1 to 13 of 13
#idstringchannelstring
1tx6ldempty
2t1bmfPhone· (raw value "Phone ")
3t6s3mTELEPHONE
4t7f5e·email (raw value " email")
5tsvpjWeb Chat
6ta4ene mail
7tacytWebChat· (raw value "WebChat ")
8t95p3·· (raw value " ")
9t9ulvchat
10t9k3me-mail⇥ (raw value "e-mail\t")
11tzj97missing
12t22bjTELEPHONE
13tk313web-chat

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