加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 折叠动作如何在Spark中起作用?

发布时间:2020-12-16 19:21:34 所属栏目:安全 来源:网络整理
导读:下面我有一个Spark折叠动作的 Scala示例: val rdd1 = sc.parallelize(List(1,2,3,4,5),3)rdd1.fold(5)(_ + _) 这会产生输出35.有人可以详细解释这个输出是如何计算的吗? 解决方法 取自Scaladocs here(强调我的): @param zeroValue the initial value for
下面我有一个Spark折叠动作的 Scala示例:

val rdd1 = sc.parallelize(List(1,2,3,4,5),3)
rdd1.fold(5)(_ + _)

这会产生输出35.有人可以详细解释这个输出是如何计算的吗?

解决方法

取自Scaladocs here(强调我的):

@param zeroValue the initial value for the accumulated result of each
partition for the op operator,and also the initial value for the
combine results from different

partitions for the op operator – this will typically be the neutral
element (e.g. Nil for list concatenation or 0 for summation)

在你的情况下,zeroValue被添加了四次(每个分区一个,加上一个来自分区的结果).结果是:

(5 + 1) + (5 + 2 + 3) + (5 + 4 + 5) + 5 // (extra one for combining results)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读