赞
踩
val newRdd = oldRdd. mapValues(func)
def mapValues[U](f : scala.Function1[V, U]) : org.apache.spark.rdd.RDD[scala.Tuple2[K, U]] = { /* compiled code */ }
针对于(K,V)形式的类型只对V进行操作
package com.day1 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} object oper { def main(args: Array[String]): Unit = { val config:SparkConf = new SparkConf().setMaster("local[*]").setAppName("wordCount") // 创建上下文对象 val sc = new SparkContext(config) // mapValues算子 val arrayRdd = sc.makeRDD(Array((4,"刘六"),(2,"李四"),(3,"王五"),(1,"张三"))) val mapRdd = arrayRdd.mapValues(_+"?") mapRdd.collect().foreach(println) } } 输入 (4,"刘六") (2,"李四") (3,"王五") (1,"张三") 输出 (4,"刘六?") (2,"李四?") (3,"王五?") (1,"张三?")
无
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。