map对每个元素进行映射

test.txt
1       a1
2       a2
3       a3
d       a4
val test = sc.textFile("/user/zhaoja/test/input/test.txt")
val a = test.flatMap{line=>line.split('\t')}
val b = test.map{line=>line.split('\t')}
a.foreach(println)
scala> a.take(1).foreach(println)
1
scala> b.take(1)(0)(0)
res47: String = 1

 

posted on 2017-07-14 16:20  充实自己  阅读(323)  评论(0编辑  收藏  举报