mapValues

只关心values
针对于(K,V)形式的类型只对V进行操作

package com.atguigu

import org.apache.spark.rdd.RDD
import org.apache.spark.{HashPartitioner, Partitioner, SparkConf, SparkContext}

object Trans {
  def main(args: Array[String]): Unit = {

    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("Spark01_Partition")
    //构建spark上下文对象
    val sc = new SparkContext(conf)

    val rdd: RDD[(Int, String)] = sc.makeRDD(Array((3,"aa"),(6,"bb"),(1,"cc"),(4,"dd")))
    val rdd1: RDD[(Int, String)] = rdd.mapValues(_+"|||")

    rdd1.foreach(println)

    sc.stop()
  }
}

(3,aa|||)
(6,bb|||)
(1,cc|||)
(4,dd|||)

你可能感兴趣的:(mapValues)