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)
}

}
posted @ 2021-08-22 20:18  tonggang_bigdata  阅读(83)  评论(0编辑  收藏  举报