JerryLead / SparkInternals

Notes talking about the design and implementation of Apache Spark

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

关于第二章JobLogicalPlan的一点小意见

sunbuhui opened this issue · comments

“groupByKey() 没有在 map 端进行 combine,因为 map 端 combine 只会省掉 partition 里面重复 key 占用的空间,当重复 key 特别多时,可以考虑开启 combine。”这一句
根据我从stackoverflow上查到的 “groupByKey doesn't know whether map side aggregations would save anything and how to do them as it has no information on the aggregation you are planning to do (if any). reduceByKey or combineByKey are provided with an aggregate function which means spark can actually do this optimization.”,groupbykey这么设计是因为它不能自定义聚合函数,spark不知道groupbykey之后用户要干什么,所以不combine,感觉这个“只能节约空间”和没有combine没有直接关联

@key2Love stackoverflow上讲的是groupByKey()、reduceByKey()和combineByKey()的区别。我这里说的主要是如何高效实现groupByKey()。 对于groupByKey()的实现来说,虽然groupByKey()没有aggregation函数,但是在实现时仍然可以在map端将相同key的values聚合起来得到[key, list(v1, v2, ..., vn)],只是聚合成list后由于没有aggregation函数,无法降低[list(v1, v2, ..., vn)]占用的空间大小。但是,此时如果相同的key比较多时,这样聚合起来会减少相同key占用的空间。