Skip to main content
PYSPARK • LESSON 174

Small-Table Broadcast Joins with broadcast()

How do we broadcast a small lookup dimension table to all executors to eliminate a costly SortMergeJoin shuffle?

Expert2 Minutes980 XP
🤔 THE QUESTION

How do we broadcast a small lookup dimension table to all executors to eliminate a costly SortMergeJoin shuffle?

💡 WHAT IS IT?

broadcast(smallDF) copies the small table to every executor node, transforming the join into a BroadcastHashJoin.

🎯 WHAT IS IT USED FOR?

Massively accelerating joins between massive fact tables (billions of rows) and small dimension tables.

💻 EXAMPLE
from pyspark.sql.functions import broadcast

optimized_join = large_fact.join(broadcast(small_dim), "country_code", "inner")

🎯 Mission Objectives

Practice typing production-grade PySpark code for Small-Table Broadcast Joins with broadcast().

  • Import broadcast function
  • Wrap small dimension DataFrame in broadcast()
  • Execute zero-shuffle BroadcastHashJoin