saveAsTextFile()写的最后RDD单文本文件 - 阿帕奇星火 [英] saveAsTextFile() to write the final RDD as single text file - Apache Spark
问题描述
我正在使用Apache星火批处理应用程序,我想写最终RDD为文本文件,目前我使用可用的 saveAsTextFile(文件路径)
方法在RDD。
I am working on a batch application using Apache Spark, i wanted to write the final RDD as text file, currently i am using saveAsTextFile("filePath")
method available in RDD.
我的文本文件包含 \\ U0001
分隔符分隔的字段。因此,在模型类的toString()方法,我加入分隔的所有字段 \\ U0001
分隔符。
My text file contains the fields delimited with \u0001
delimiter. So in the model class toString() method i added all the fields seperated with \u0001
delimiter.
这是处理这个正确的方式?或任何其他最好的方法可用?
is this the correct way to handle this? or any other best approach available?
另外如果我遍历RDD和写入使用文件内容的FileWriter
中的Java类可用?
Also what if i iterate the RDD and write the file content using FileWriter
class available in Java?
请告知这一点。
问候,
尚卡尔
Regards, Shankar
推荐答案
要写成一个单一的文件中,有几个选项。如果你的写作HDFS或类似的分布式的商店,你可以先合并
您的RDD到单个分区(注意:那么你的数据必须适合于一个工人),或者你可以收集
数据到驱动程序,然后使用一个FileWriter。
To write as a single file there are a few options. If your writing to HDFS or a similar distributed store you can first coalesce
your RDD down to a single partition (note your data must then fit on a single worker), or you could collect
the data to the driver and then use a filewriter.
这篇关于saveAsTextFile()写的最后RDD单文本文件 - 阿帕奇星火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!