-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第三章《Spark 逻辑处理流程》勘误与修改建议 #4
Comments
Page 65, 图 3.13 的 2,k, 3,e 为啥不是2,k1, 3,e1 |
@isplendid 因为combineByKey中的createCombiner()只会作用于相同key的第一个record。在本例中,处理<2, b>时发现key=2没有被处理过,所以使用createCombiner()将b转换为b1,得到<2, b1>,保存在内存中。接下来处理<2, k>,由于key=2已经被处理过(在内存中),所以使用mergeValue()来处理<2, k>,也就是mergeValue(<2, b1>, <2, k>) => <2, b1+k>。 可以使用下面的示例程序来验证: import org.apache.spark.sql.SparkSession
object CombineByKeyExample {
def main(args: Array[String]): Unit = {
val spark = SparkSession
.builder
.appName("combine by key example")
.master("local[2]")
.getOrCreate()
val sc = spark.sparkContext
val inputRDD = sc.parallelize(Array[(Int, Char)](
(1, 'a'), (2, 'b'), (2, 'k'), (3, 'c'), (4, 'd'), (3, 'e'),
(3, 'f'), (2, 'g'), (2, 'h')
), 3)
println("-----------input RDD--------")
inputRDD.mapPartitionsWithIndex((pid, iter) => {
iter.map(value => "PID: " + pid + ", value: " + value)
}).foreach(println)
val resultRDD = inputRDD.combineByKey((v: Char) => {
if (v == 'c') {
v + "0"
} else {
v + "1"
}
}
, (c: String, v: Char) => c + "+" + v, (c1: String, c2: String) => c1 + "_" + c2, 2)
// val resultRDD = inputRDD.combineByKey((v:Char)=>List(v), (c:List[Char],v:Char)=>v::c,(c1:List[Char],c2:List[Char])=>c1:::c2)
println(resultRDD.toDebugString)
println("-----------result RDD--------")
resultRDD.mapPartitionsWithIndex((pid, iter) => {
iter.map(value => "PID: " + pid + ", value: " + value)
}).foreach(println)
}
}
|
Page 61, aggregateByKey()操作的标题前的倒数第三行末尾起 |
@swordspoet 多谢指出,下次印刷时会进行更正。 |
@zeahoo 多谢指出,下次印刷时会进行更正。 |
P74:“Key是Int类型,并从[0, numPartitions)中随机生成,……”。其中Key的范围是不是都应该是闭区间,不然就对不上P73图(2)中展示的Key——若不包含2,那么随机生成的整型如何得到2,接下来的record的Key+1又怎么得到3? |
P87:图3.31(3)中MapPartitionsRDD有误 |
@JerryLead 2020 10 月 第二次印刷的版本,里面第86页的内容 缺失,变成了第96页的内容, |
感谢指出,目前代码实现是[0, numPartitions),生成的key应该是[0, 2),图中的key应该都减去1。 |
@wangdxh |
page 52,图3.5,filter图示中,对于tuple
结果写成了 |
P61,页面中间那段:在性能上,相比groupByKey()、reduceByKey()可以在Shuffle之前使用func... |
P67图3.15中的文字跟其他图片的字体不一样 |
P73 左下角的图,最后一个分区,应该是 3, (5, e); 4, (2, g) ,而不是 3, (5, e) ; 6, (2, g) 吧?Key不是递增的吗? |
P80 图 3.25 中的 rdd3 左边第一个分区,rdd1 中还包含 (1, b) 的吧? |
No description provided.
The text was updated successfully, but these errors were encountered: