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

}
上一篇:报错:For input string: ""


下一篇:CSS-JQUERY笔记