Skip to content
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

Open
JerryLead opened this issue Jul 20, 2020 · 18 comments
Open

第三章《Spark 逻辑处理流程》勘误与修改建议 #4

JerryLead opened this issue Jul 20, 2020 · 18 comments

Comments

@JerryLead
Copy link
Owner

No description provided.

@isplendid
Copy link

Page 65, 图 3.13 的 2,k, 3,e 为啥不是2,k1, 3,e1

@JerryLead
Copy link
Owner Author

@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)
  }
}

@zeahoo
Copy link

zeahoo commented Sep 22, 2020

Page 61, aggregateByKey()操作的标题前的倒数第三行末尾起
在性能上,相比groupBykey()、reduceByKye()可以在Shuffle之前使用func对数据进行聚合,减少了……
这边的顿号应该改为逗号

@swordspoet
Copy link

第54页的表格内sampleByKey()的例子中的“用法”中应该是rdd2 = rdd1.sampleByKey(true,map)
image

@swordspoet
Copy link

第56页,list应该为List
image

@JerryLead
Copy link
Owner Author

@swordspoet 多谢指出,下次印刷时会进行更正。

@JerryLead
Copy link
Owner Author

@zeahoo 多谢指出,下次印刷时会进行更正。

@yshdzw
Copy link

yshdzw commented Dec 23, 2020

P74:“Key是Int类型,并从[0, numPartitions)中随机生成,……”。其中Key的范围是不是都应该是闭区间,不然就对不上P73图(2)中展示的Key——若不包含2,那么随机生成的整型如何得到2,接下来的record的Key+1又怎么得到3?

@yshdzw
Copy link

yshdzw commented Dec 23, 2020

P87:图3.31(3)中MapPartitionsRDD有误

@wangdxh
Copy link

wangdxh commented Jan 20, 2021

@JerryLead 2020 10 月 第二次印刷的版本,里面第86页的内容 缺失,变成了第96页的内容,
96页的也还是96页的内容,能不能拍张86页的照片?

@JerryLead
Copy link
Owner Author

P74:“Key是Int类型,并从[0, numPartitions)中随机生成,……”。其中Key的范围是不是都应该是闭区间,不然就对不上P73图(2)中展示的Key——若不包含2,那么随机生成的整型如何得到2,接下来的record的Key+1又怎么得到3?

感谢指出,目前代码实现是[0, numPartitions),生成的key应该是[0, 2),图中的key应该都减去1。

@JerryLead
Copy link
Owner Author

@wangdxh
我这里只有第一版的,我把85页、86页、87页都拍了照发在这里:
WechatIMG234
WechatIMG235
WechatIMG236

@xpleaf
Copy link

xpleaf commented May 19, 2021

page 52,图3.5,filter图示中,对于tuple

2,g

结果写成了2_g

@midKingKing
Copy link

page65中的图3.13右侧应该是3,(c0+e, f1) -> 3, c0+e_f1
微信图片_20210703231757

@ycli12
Copy link

ycli12 commented Feb 26, 2022

P61,页面中间那段:在性能上,相比groupByKey()、reduceByKey()可以在Shuffle之前使用func...
、应该改成逗号

@ycli12
Copy link

ycli12 commented Apr 12, 2022

P67图3.15中的文字跟其他图片的字体不一样

@uxgnoz
Copy link

uxgnoz commented Jun 7, 2022

P73 左下角的图,最后一个分区,应该是 3, (5, e); 4, (2, g) ,而不是 3, (5, e) ; 6, (2, g) 吧?Key不是递增的吗?

@uxgnoz
Copy link

uxgnoz commented Jun 7, 2022

P80 图 3.25 中的 rdd3 左边第一个分区,rdd1 中还包含 (1, b) 的吧?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants