键值转换操作

Posted on 2018-08-14 16:02  打杂滴  阅读(150)  评论(0编辑  收藏  举报

partitionBy

mapValues

flatMapValues

combineByKey

scala> aa.collect

res77: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

scala> val mapRDD=aa.map(x=>(TaskContext.getPartitionId,x))

mapRDD: org.apache.spark.rdd.RDD[(Int, Int)] = MapPartitionsRDD[109] at map at <console>:28

scala> mapRDD.combineByKey((v:Int)=>v+"_" ,(c:String,v:Int)=>c+"$"+v, (c1:String,c2:String)=>c1+"%"+c2).collect

res78: Array[(Int, String)] = Array((0,1_$2), (1,3_$4$5), (2,6_$7), (3,8_$9$10))

foldByKey

reduceByKey

groupByKey

cogroup  相当于SQL中的全外连接,返回左右RDD中的记录,关联不上为空

join. fullOuterJoin .leftOuterJoin.rightOutJoin都是针对RDD[K,V]中的K值相等的操作,分别对应内连接,全连接,左连接,右连接,这些操作都是调动cogroup进行实现的。

subtractByKey  删掉 RDD 中键与 other RDD 中的键相同的元素

Copyright © 2024 打杂滴
Powered by .NET 8.0 on Kubernetes