According to Learning Spark
Keep in mind that repartitioning your data is a fairly expensive operation. Spark also has an optimized version of
I would like to add to Justin and Power's answer that -
repartition
will ignore existing partitions and create new ones. So you can use it to fix data skew. You can mention partition keys to define the distribution. Data skew is one of the biggest problems in the 'big data' problem space.
coalesce
will work with existing partitions and shuffle a subset of them. It can't fix the data skew as much as repartition
does. Therefore even if it is less expensive it might not be the thing you need.