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?

Expertโฑ 2 Minutesโญ 980 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