Key Salting
Key salting adds a secondary value to split one logical key into subgroups. Derive the salt from a stable row identity for repeatable assignment. Hashing only the original hot key does not split its rows.
For sum and count, group by key and salt, then merge the partial sums and counts by the original key. An average requires sum and count; adding distinct counts or medians is generally incorrect. Numeric overflow and floating-point order still need attention.
For a left join with facts on the left, assign each hot fact one salt and replicate every matching right row across the salt range. Keep cold keys on a single salt. Verify duplicate multiplicity and unmatched rows. Right and full outer joins need additional reasoning about replicated unmatched right rows.
Eight salts do not guarantee eight physical partitions because hashes can collide and adaptive execution can change task layout. Salting also adds state and possibly another shuffle. Built-in partial aggregation may already remove the relevant bottleneck, so test whether salting helps the actual workload.
See Spark Partitioning, Shuffles, and Data Skew for worked examples.
Reference: Apache Spark documentation.
Discover more from Insightful Data Lab
Subscribe to get the latest posts sent to your email.
