FlatMap

package sparkcore

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

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

val conf: SparkConf = new SparkConf().setAppName("FlatMap").setMaster("local")

val sc = new SparkContext(conf)

val lineRDD: RDD[String] = sc.parallelize(List("java,spark,hadoop","spark,java,hadoop"))

/**
* flatMap:将一行转换成多行
*/
val wordsRDD: RDD[String] =lineRDD.flatMap(line=>{
println("flatMap:"+line)
line.split(",")
})
wordsRDD.foreach(println)
}

}

FlatMap

上一篇:linux与linux,linux与windows之间用SSH传输文件


下一篇:git巨坑,提交代码时本地工作区被覆盖