A 40 MB lookup table is making Spark shuffle 2 TB of orders. Learn how Spark picks a join and how to overrule it.
Adding customer segments to 2 TB of orders takes 47 minutes. The SQL tab shows why: a SortMergeJoin with an Exchange under each side. All 2 TB of orders are hashed by customer_id and shipped across the network, just to meet a table that would fit in memory on every executor.
Spark didn't broadcast customers because its estimated size, 40 MB, is above the 10 MB default threshold. To fix it on purpose (and know when not to) you need to know the join strategies and how Spark chooses between them.
orders = spark.read.parquet("s3://lake/orders/") # ~2 TB
customers = spark.read.parquet("s3://lake/customers/") # ~40 MB
enriched = orders.join(customers, "customer_id", "left")
enriched.write.mode("overwrite").parquet("s3://lake/enriched/")Reach the last step for the run summary: the key takeaways from this lesson.