【发布时间】:2015-12-03 23:43:56
【问题描述】:
我看到了以下帖子:Understanding TreeReduce in Spark
我仍在尝试准确了解何时使用 treeReduce 和 reduceByKey。我认为我们可以使用一个通用示例,例如字数统计来帮助我进一步了解正在发生的事情。
- 在字数统计中使用 reduceByKey 总是有意义吗?
- 或者当 treeReduce 更有意义时,是否存在特定大小的数据?
- 当 treeReduce 是更好的选择时,是否有特殊情况或经验法则?
- 这也可以在上面基于 reduceByKey 得到回答,但使用 reduceByKeyLocally 和 treeReduce 会发生任何变化
- 如何正确确定深度?
编辑:所以在 spark-shell 中玩,我想我根本不了解 treeReduce 的概念,但希望一个例子和这些问题有所帮助。
res2: Array[(String, Int)] = Array((D,1), (18964,1), (D,1), (1,1), ("",1), ("",1), ("",1), ("",1), ("",1), (1,1))
scala> val reduce = input.reduceByKey(_+_)
reduce: org.apache.spark.rdd.RDD[(String, Int)] = ShuffledRDD[11] at reduceByKey at <console>:25
scala> val tree = input.treeReduce(_+_, 2)
<console>:25: error: type mismatch;
found : (String, Int)
required: String
val tree = input.treeReduce(_+_, 2)
【问题讨论】:
标签: apache-spark