CertLumen

Databricks Data Analyst Associate · Section 2 · 8% of the exam

Perform data cleaning on Unity Catalog Tables in SQL, including removing invalid data or handling missing values.

One of the objectives of the Databricks Certified Data Analyst Associate exam, in the section “Managing Data”. Here is what it covers, the points to remember and a question to try.

What it covers

Clean data with ordinary Databricks SQL. Profile the table, standardise text, convert types safely with try_ functions, handle NULLs and blanks, remove invalid rows and duplicates, write the result to a clean table, and add constraints so bad data cannot return.

Points to remember

  • Keep bronze raw. Write a cleaned silver table with CREATE OR REPLACE TABLE ... AS SELECT, or use a view, instead of deleting from the source.
  • Profile first: count(*), count(col) (non-NULL only), count_if(cond) and count(DISTINCT key). The notebook Data Profile shows statistics and histograms.
  • Use IS NULL, never = NULL. Blank strings are not NULL, so convert them with nullif(trim(col), '').
  • Missing values: coalesce / ifnull / nvl for defaults, nvl2 for flags, a median or mean for imputation, or drop rows whose key is missing.
  • With ANSI mode on, CAST of a bad value fails the query. try_cast, try_to_number and try_to_timestamp return NULL instead.

Try a question

In main.sales.orders, the column discount_pct is NULL when no discount was applied. A report needs the value 0 in those rows. Which expression returns the correct value?

  1. Anullif(discount_pct, 0)
  2. BCASE WHEN discount_pct = NULL THEN 0 ELSE discount_pct END
  3. Ccoalesce(discount_pct, 0)
  4. Dnvl2(discount_pct, 0, discount_pct)
Show the answer

C. coalesce returns its first non-NULL argument, so NULL discounts become 0 and real values are kept. ifnull(discount_pct, 0) and nvl(discount_pct, 0) are equivalent two-argument forms.

Written for practice in the style of the exam: never a question from the real exam.

In the course

The lesson Cleaning Unity Catalog Tables with SQL teaches this objective (about 45 minutes), and 10 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.

More in this section

← Previous objective · All 39 objectives · Next objective →