1. A data engineer is using PySpark in a Microsoft Fabric Notebook to join a large fact table (500 million rows) with a small product dimension table (10,000 rows). During testing, the job runs very slowly, and the Spark UI shows many shuffle operations during the join. Which optimization should the data engineer apply to eliminate the shuffle and improve join performance?
- A. Replace the default join with a broadcast join by wrapping the smaller DataFrame with broadcast(), allowing each executor to receive a local copy of the dimension table.✓ Correct
- B. Increase the number of shuffle partitions using spark.conf.set('spark.sql.shuffle.partitions', '800') to distribute the shuffle more evenly.
- C. Repartition the large fact table to match the number of partitions in the dimension table before performing the join.
- D. Cache the large fact table using df.cache() before the join to prevent re-reading it from storage.
Explanation
Option A is correct because a broadcast join sends the small dimension table to every executor as an in-memory copy, completely eliminating the shuffle exchange that occurs when Spark tries to co-locate matching rows across partitions. This is the standard PySpark optimization for skewed or slow joins when one side is small enough to fit in memory. Option B is incorrect because increasing shuffle partitions only redistributes the shuffle work across more partitions; it does not eliminate the shuffle itself and may introduce overhead for small datasets. Option C is incorrect because repartitioning the large fact table to match the small table's partition count would reduce parallelism dramatically and still does not remove the shuffle; it would likely make performance worse. Option D is incorrect because caching the large fact table helps if it is reused multiple times, but does not address the root cause — the shuffle during the join itself.