coalesce:不需要shuffle, 最大线程数,并行度受分区数的影响,如果合并成的分区数过少,可以采用repartition
def coalesce(numPartitions: Int): Dataset[T] = withTypedPlan { Repartition(numPartitions, shuffle = false, logicalPlan) }
repartition: 需要进行shuffle,并行度很高.扩大分区的时候使用,还有就是在合并分区过少的时候使用,以免影响并行度
def repartition(numPartitions: Int): Dataset[T] = withTypedPlan { Repartition(numPartitions, shuffle = true, logicalPlan) }