【问题标题】:Does coalesce(numPartitions) in spark undergo shuffling or not?spark中的 coalesce(numPartitions) 是否进行改组?
【发布时间】:2017-02-03 22:55:26
【问题描述】:

我有一个关于火花变换函数的简单问题。

coalesce(numPartitions) - 将 RDD 中的分区数减少到 numPartitions。对于过滤大型数据集后更有效地运行操作很有用。

val dataRDD = sc.textFile("/user/cloudera/inputfiles/records.txt")
val filterRDD = dataRDD.filter(record => record.split(0) == "USA")
val resizeRDD = filterRDD.coalesce(50)
val result    = resizeRDD.collect

我的问题是

  1. coalesce(numPartitions) 是否真的会从 filterRDD 中移除空分区?

  2. coalesce(numPartitions) 是否进行洗牌?

【问题讨论】:

    标签: apache-spark


    【解决方案1】:

    coalesce 转换用于减少分区数量。如果输出分区的数量小于输入,则应使用coalesce。它可以根据默认禁用的 shuffle 标志(即 false)触发 RDD shuffle。

    如果分区数大于当前分区数,并且您使用coalesce 方法没有 shuffle=true 标志,则分区数保持不变。coalesce 不保证将删除空分区。比如你有20个空分区和10个有数据的分区,那么在你调用rdd.coalesce(25)之后仍然会有空分区。如果您使用coalesce 并将shuffle 设置为true,那么这将等效于repartition 方法,并且数据将均匀分布在分区中。

    【讨论】:

    • 另外,在使用coalesce 时必须牢记的一件事是它可能会导致并行度降低。详情见this discussion
    猜你喜欢
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2018-05-08
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    相关资源
    最近更新 更多