Problems / Coalesce Fallback Chain / Editorial
COALESCE
COALESCE(mobile_phone, home_phone, work_phone, 'unknown')
'unknown'
customer_id
Fallback chains are what COALESCE was made for. The equivalent CASE WHEN mobile_phone IS NOT NULL THEN mobile_phone WHEN home_phone IS NOT NULL THEN ... END grows linearly in noise with each tier, while COALESCE stays one readable call no matter how many fallbacks you add. Two things to remember: argument order is priority order, and a constant final argument acts as a guaranteed default. PySpark mirrors this exactly with F.coalesce(col1, col2, ..., F.lit(default)).
CASE WHEN mobile_phone IS NOT NULL THEN mobile_phone WHEN home_phone IS NOT NULL THEN ... END
F.coalesce(col1, col2, ..., F.lit(default))
Solve Coalesce Fallback Chain yourself →