当我运行完一个Spark程序想把结果保存为saveAsTextFile,
结果使用hadoop fs -ls la /qy/151231.txt后发现里面有一系列的part,好几千个。
原因:
运行Spark的时候把数据分成了很多份(partition),每个partition都把自己的数据保存在partxxx文件夹。
如果想保存为一份的话,就要:
先collect
或者
data.coalesce(1,true).saveAsTextFile()
You can also use repartition(1), which is just a wrapper for coalesce() with the suffle argument set to true.
但是如果你的数据很多,还是不要这样做了。
如果已经存了很多个part:
可以把大文件夹getmerge:
hadoop fs -getmerge /output/dir/on/hdfs/ /desired/local/output/file.txt
hadoop fs -getmerge /qy/151231 /usr/qy/data/151231.txt
也可以:
data.coalesce(1,true).saveAsTextFile()
You can also use repartition(1), which is just a wrapper for coalesce() with the suffle argument set to true.
但是如果你的数据很多,还是不要这样做了。
如果已经存了很多个part:
可以把大文件夹getmerge:
hadoop fs -getmerge /output/dir/on/hdfs/ /desired/local/output/file.txt
hadoop fs -getmerge /qy/151231 /usr/qy/data/151231.txt
也可以:
hadoop fs -cat /some/where/on/hdfs/job-output/part-r-* > TheCombinedResultOfTheJob.txt
————————————————
版权声明:本文为CSDN博主「power0405hf」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/power0405hf/article/details/50596233