cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

What is the difference between coalesce and repartition when it comes to shuffle partitions in spark

aladda
Honored Contributor II
Honored Contributor II
 
1 ACCEPTED SOLUTION

Accepted Solutions

aladda
Honored Contributor II
Honored Contributor II

Coalesce essentially groups multiple partitions into a larger partitions. So use coalesce when you want to reduce the number of partitions (and also tasks) without impacting sort order.  Ex:- when you want to write-out a single CSV file output instead of multiple parts

Use repartition when you want to cause a shuffle that changes the number of partitions.  A common use-case for repartition is to remove skew in file sizes or to start out with a smaller/different number of partitions than the default in Spark

View solution in original post

1 REPLY 1

aladda
Honored Contributor II
Honored Contributor II

Coalesce essentially groups multiple partitions into a larger partitions. So use coalesce when you want to reduce the number of partitions (and also tasks) without impacting sort order.  Ex:- when you want to write-out a single CSV file output instead of multiple parts

Use repartition when you want to cause a shuffle that changes the number of partitions.  A common use-case for repartition is to remove skew in file sizes or to start out with a smaller/different number of partitions than the default in Spark