作用
案例
每个value前面添加个前缀
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}
object demo {
def main(args: Array[String]): Unit = {
val conf: SparkConf = new SparkConf().setAppName("SparkCoreTest").setMaster("local[*]")
val sc: SparkContext = new SparkContext(conf)
val rdd: RDD[(Int, String)] = sc.makeRDD(List((1, "a"), (1, "d"), (2, "b"), (3, "c")))
val newRDD: RDD[(Int, String)] = rdd.mapValues("|||" + _) //对value前面添加三个 |||
newRDD.collect().foreach(println)
/* 输出
(1,|||a)
(1,|||d)
(2,|||b)
(3,|||c)
*/
sc.stop()
}
}