How can we pre-bucket and pre-sort a table on storage so future joins on that key require zero cluster shuffling?
bucketBy(numBuckets, col).sortBy(col) pre-shuffles data during write into fixed hash buckets for instant SortMergeJoins.
Optimizing massive enterprise tables joined daily on customer_id or account_id in recurrent ETL pipelines.
df.write.bucketBy(16, "customer_id").sortBy("order_date").mode("overwrite").saveAsTable("default.bucketed_orders")Practice typing production-grade PySpark code for Bucketing Data with bucketBy() and sortBy().