如何打印RDD的内容是什么? [英] How to print the contents of RDD?
问题描述
我试图打印一个集合的内容,以星火控制台。
I'm attempting to print the contents of a collection to the Spark console.
我有一个类型:
linesWithSessionId: org.apache.spark.rdd.RDD[String] = FilteredRDD[3]
和我使用命令:
scala> linesWithSessionId.map(line => println(line))
但这种印:
RES1:org.apache.spark.rdd.RDD [单位] = MappedRDD [4]在图:19
res1: org.apache.spark.rdd.RDD[Unit] = MappedRDD[4] at map at :19
我怎么能写RDD到控制台或将其保存到磁盘,所以我可以查看它的内容?
How can I write the RDD to console or save it to disk so I can view its contents?
推荐答案
的地图
函数是一个的转换的,这意味着星火不会直到在其上运行的动作的实际评估您的RDD。
The map
function is a transformation, which means that Spark will not actually evaluate your RDD until you run an action on it.
要打印,您可以使用的foreach
(这是一个动作):
To print it, you can use foreach
(which is an action):
linesWithSessionId.foreach(println)
要写入到磁盘,您可以使用从的的saveAs ...
函数(仍然动作)一个的 RDD API
To write it to disk you can use one of the saveAs...
functions (still actions) from the RDD API
这篇关于如何打印RDD的内容是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!