0%

Spark入门:RDD编程(2)

Spark入门:RDD编程(2)

4.2键值对RDD

4.2.1键值对RDD的创建

1679919962655

1
2
3
4
5
6
lines=sc.textFile("file:///usr/local/spark/mycode/rdd/word.txt")

pairRdd=lines.flatMap(lambda line:line.split(" ")).map(lambda word:(word,1))

pairRdd.foreach(print)

1679920610754

1679920024570

1679920857471

4.2.2常用键值对转换操作

1679920904927

1.reduceByKey(func)

1679920937895

1679921092076

2.groupByKey()

1679921126885

1679921148329

1679921162978

3.key

1679921231527

4.value

1679921285079

5.sortByKey()

1679921328845

6.sortBy()

1679921389676

7.mapValues(func)

1679921487925

8.join

1679921512081

4.2.3一个综合实例

1679921667681

-------------本文结束感谢您的阅读-------------
老板你好,讨口饭吃