RDD常用算子
1.map(Func)
val sentence = Array(
"Hello world ! I am an engineer ! good bye world!","good bye world !"
)
val strdd = sc.parallelize(sentence)
val wordcount = strdd.flatMap(line => line.split(" ")).map(line => (line,1)).groupByKey().map(a=>(a._1,a._2.sum)).collect
2.flatMap(fun) 将map的结果中list展开
val sentence = Array(
"Hello world ! I am an engineer ! good bye world!","good bye world !"
)
val strdd = sc.parallelize(sentence)
val wordcount = strdd.flatMap(line => line.split(" ")).map(line => (line,1))