spark flatMapValues无法在diff行中分离

时间:2018-06-06 03:28:06

标签: apache-spark flatmap

如何使用foreach(println)将下面的代码分隔成diff行:

sc.textFile("/user/edureka_366833/spark/fmapvalue")
   .map(_.split('\t'))
   .map(a=>(a(0),a(1)))
   .flatMapValues(a=>(a.split(':')))

scala>  
sc.textFile("/user/edureka_366833/spark/fmapvalue")
  .map(_.split('\t')).map(a=>(a(0),a(1)))
  .flatMapValues(a=>(a.split(':'))).collect

res5: Array[(String, String)] = Array((0001,a), (0001,b), (0001,c), 
          (0002,d), (0002,e), (0002,f), (0003,g), (0003,h), (0003,i), 
          (0004,j), (0004,k), (0004,l))

scala>  
sc.textFile("/user/edureka_366833/spark/fmapvalue")
  .map(_.split('\t')).map(a=>(a(0),a(1)))
  .flatMapValues(a=>(a.split(':')))
  .foreach(println)

没有返回任何内容

0 个答案:

没有答案