How do we add random salt keys to skewed fact records and explode the dimension to eliminate join bottlenecks?
Salting splits high-cardinality hot keys into multiple sub-keys across cluster executors to eliminate join skew.
Fixing long-tail straggler tasks in massive joins where 1% of keys contain 90% of row volume.
from pyspark.sql.functions import concat, lit, rand
skewed_sales = sales.withColumn("salt", (rand() * 10).cast("int"))
salted_dim = dim.withColumn("salt", explode(array([lit(i) for i in range(10)])))
balanced_join = skewed_sales.join(salted_dim, ["key", "salt"], "inner").drop("salt")Practice typing production-grade PySpark code for Salting Large Joins to Mitigate Data Skew.