无法看到RDD内容 [英] Not able to see RDD contents

查看:49
本文介绍了无法看到RDD内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Scala创建RDD,但是当我尝试查看RDD的内容时,我得到的结果低于

i am using scala to create an RDD but when i am trying to see the contents of RDD i am getting below results

MapPartitionsRDD[25] at map at <console>:96

我想查看RDD的内容,怎么看呢?

I want to see the contents of RDD how can i see that ?

下面是我的scala代码:

below is my scala code:

 object WordCount {
   def main(args: Array[String]): Unit = {
     val textfile = sc.textFile("/user/cloudera/xxx/File")
     val word = textfile.filter(x => x.length >  0).map(_.split('|'))
     println(word)
   }
}

推荐答案

您需要提供输出转换(操作).例如使用 RDD.collect :

You need to provide an output transformation (action). e.g. use RDD.collect:

object WordCount {
   def main(args: Array[String]): Unit = {
     val textfile = sc.textFile("/user/cloudera/xxx/File")
     val word = textfile.filter(x => x.length >  0).map(_.split('|'))
     word.collect().foreach(println)
   }
}

如果您有 Array [Array [T]] ,则需要先 flatten ,然后再使用 foreach :

If you have an Array[Array[T]], you'll need to flatten before using foreach:

word.collect().flatten.foreach(println)

这篇关于无法看到RDD内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆