【问题标题】:What is the Difference between mapPartitions and foreachPartition in Apache SparkApache Spark 中的 mapPartitions 和 foreachPartition 有什么区别
【发布时间】:2018-08-14 23:48:30
【问题描述】:

我有一个 DataFrame,其中一列有逗号分隔的数据。

例如:数据如下所示: [{value:1}, {value:2, value:3}, {some value}, {somevalue, othervalue}]

该列是字符串数据类型。我想将其转换为 List 并应用一些功能。 现在我有一个函数可以将 String 列转换为 List 和其他应用逻辑。

但是哪个函数会更好和优化,因为我们有 2 个类似的探测函数 ma​​pPartitionsforeachPartitions,它是否具有完全相同的性能以及在哪个函数中使用场景??

【问题讨论】:

标签: apache-spark pyspark pyspark-sql


【解决方案1】:

区别与map和foreach相同。在这里寻找好的解释 - Is there a difference between foreach and map?

mapPartitions 和 foreachPartitions 是适用于 Dataframe 的每个 partition 而非每个 element 的转换/操作。有关对比地图和 mapPartitions 的说明,请参见此处 - Apache Spark: map vs mapPartitions?

根据您的描述,听起来您想要 map 或 foreach。

【讨论】:

    猜你喜欢
    • 2016-06-23
    • 2016-06-05
    • 2014-06-24
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 2021-11-19
    • 2015-12-05
    • 1970-01-01
    相关资源
    最近更新 更多