I would suggest you to try setting spark.sql.shuffle.partitions to 2001, if you're running out of memory on the shuffle,.
Whenever the number of partitions is greater than 2000, Spark uses a different data structure for shuffle book-keeping:
private[spark] object MapStatus {
def apply(loc: BlockManagerId, uncompressedSizes: Array[Long]): MapStatus = {
if (uncompressedSizes.length > 2000) {
HighlyCompressedMapStatus(loc, uncompressedSizes)
} else {
new CompressedMapStatus(loc, uncompressedSizes)
}
}
…
I really wish they would let you configure this independently.
Note: Found this information in a Cloudera slide deck.
If you want to know more about Spark, then do check out this awesome video tutorial: