Databricks - Data Engineer Professional Study Guide

    3: Data Transformation, Cleansing, and Quality

    This chapter covers the Silver-layer transformation craft expected of a Databricks Data Engineer Professional: writing advanced Spark SQL and PySpark patterns that scale across window functions, joins, and aggregations, and building a quarantine pipeline that isolates bad rows from the main flow using Lakeflow Spark Declarative Pipelines expectations or Auto Loader patterns in classic jobs. Every pattern is tied to the Adaptive Query Execution behavior, Photon vectorization, and Delta Lake layout choices that determine whether the resulting Silver table is cheap to query or buried in shuffle and small files.

    Learning Objectives

    By the end of this chapter, you will be able to:

    • Write efficient Spark SQL and PySpark code to apply advanced data transformations, including window functions, joins, and aggregations, to manipulate and analyze large datasets.
    • Develop a quarantining process for bad data with Lakeflow Spark Declarative Pipelines, or Auto Loader in classic jobs.

    Executive Summary

    • Window functions and aggregations are the two highest-cost shuffle patterns in Silver pipelines, and the choice of partition keys, sort keys, and frame boundaries decides whether the stage spills or finishes in memory.
    • Spark SQL and the DataFrame API compile through the same Catalyst planner, so the production choice is rarely about performance and almost always about testability, parameterization, and version control under Databricks Asset Bundles.
    • Joins are governed by Adaptive Query Execution: broadcast hints, skew handling, and dynamic partition coalescing each have a specific trigger condition you must recognize during query-profile review.
    • Quarantine for bad data has two canonical surfaces: EXPECT ... ON VIOLATION DROP ROW (or fail / warn) inside Lakeflow Spark Declarative Pipelines, and badRecordsPath plus _rescued_data inside Auto Loader classic jobs. The right choice depends on whether the pipeline is declarative or imperative, and whether bad rows must be re-processable or only inspected.

    Assumptions

    • The reader has completed Chapters 1 and 2, has a Unity Catalog enabled workspace, and uses Databricks Runtime with Photon enabled unless explicitly stated.
    • Code samples use a fictional Silver project rooted at catalog prod_silver and schema sales, with Bronze sources at prod_bronze.sales.
    • Lakeflow Spark Declarative Pipelines is the canonical name for what older Databricks materials call DLT; the in-code Python decorators remain @dlt.* and the SQL keywords remain LIVE and STREAMING LIVE, but the product surface is Lakeflow SDP.
    • All commands assume a Unity Catalog three-part name (catalog.schema.table).

    Sections in this chapter

    1. Free
    2. Free with account
    3. Free with account