Databricks - Data Engineer Associate Study Guide

    3: Data Transformation and Modeling

    This chapter walks through refining raw bronze data into reliable silver and gold tables on the Databricks Data Intelligence Platform using PySpark and SQL. It covers cleaning patterns, joins, column and row manipulation, deduplication and aggregation, the tuning knobs that govern transformation cost, the gold-layer object catalog in Unity Catalog, and the data quality controls that keep downstream consumers protected.

    Learning Objectives

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

    • Implement data cleaning by reading bronze tables with PySpark/SQL, handling nulls, standardizing data types, and writing to silver tables.
    • Combine DataFrames using inner, left, broadcast, multi-key, cross joins, union, and union all.
    • Manipulate columns, rows, and table structures (add, drop, split, rename columns; apply filters; explode arrays).
    • Perform deduplication and aggregation operations (count, approximate count distinct, mean, summary).
    • Understand basic tuning parameters (spark.sql.shuffle.partitions, spark.default.parallelism, executor/driver memory, autoBroadcastJoinThreshold) and re-measure performance.
    • Understand and build gold-layer objects (materialized views, views, streaming tables, and tables) for BI and analytics teams in Unity Catalog.
    • Apply data quality checks and validation rules to produce reliable silver and gold datasets.

    Executive Summary

    • Silver tables are where bronze data becomes typed, deduplicated, null-handled, and conformed; the silver pass is the contract every downstream join, aggregate, and dashboard depends on.
    • Join selection (inner, left, broadcast, multi-key, cross) governs both correctness and shuffle volume; the broadcast hint is the single largest lever for collapsing a skewed join between a large fact and a small dimension.
    • Tuning is iterative: change one knob (shuffle partitions, broadcast threshold, executor memory), rerun, and compare wall clock plus shuffle metrics in the Spark UI rather than guessing.
    • Gold-layer object selection (table, view, materialized view, streaming table) ties directly to freshness, cost, and which compute (SQL warehouse versus Lakeflow Spark Declarative Pipelines) refreshes the object.
    • Data quality rules belong inside the pipeline definition (expectations in Lakeflow Spark Declarative Pipelines, CHECK constraints on Delta tables), not in a separate audit job that runs after data has already reached consumers.

    Assumptions

    • All tables referenced live under Unity Catalog three-level names; examples use placeholder names like prod.silver.customers.
    • Code targets the latest stable Databricks Runtime with Photon available; runtime version is left unspecified because behavior matches the latest stable release.
    • The reader is comfortable reading PySpark DataFrame code and standard Spark SQL.
    • Bronze tables are already populated from Chapter 2 ingestion paths (Auto Loader, COPY INTO, Lakeflow Connect, JDBC, REST).

    Sections in this chapter

    1. Free
    2. Free with account
    3. Free with account
    4. Free with account
    5. Free with account
    6. Free with account
    7. Free with account
    8. Free with account