其他分享
首页 > 其他分享> > FlatMap

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,String,val,FlatMap,line,SparkConf,spark
来源: https://www.cnblogs.com/xiguabigdata/p/15022266.html