java 我如何以csv格式输出hadoop结果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16329884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i output hadoop result in csv format
提问by Unmesha SreeVeni
I need to output my hadoop result in .csv format. how will i do this? My code :https://github.com/studhadoop/xml/blob/master/XmlParser11.java
我需要以 .csv 格式输出我的 hadoop 结果。我将如何做到这一点?我的代码:https: //github.com/studhadoop/xml/blob/master/XmlParser11.java
should i simply include csvoutputFormat in my code. I am using mapreduce API
我应该在我的代码中简单地包含 csvoutputFormat 吗?我正在使用 mapreduce API
myjob.sh
我的工作.sh
bin/hadoop jar /var/root/ALA/ala_jar/clsperformance.jar ala.clsperf.ClsPerf /user/root/ala_xmlrpt/Amrita\ Vidyalayam\,\ Karwar_Class\ 1\ B_ENG.xml /user/root/ala_xmlrpt-outputshell4
bin/hadoop fs -get /user/root/ala_xmlrpt-outputshell4/part-r-00000 /Users/jobsubmit
cat /Users/jobsubmit/part-r-00000 /Users/jobsubmit/output.csv
SOLUTION
解决方案
ys i was missing > in cat
是的,我失踪了 > 在猫
cat /Users/jobsubmit/part-r-00000> /Users/jobsubmit/output.csv
回答by Rags
You can use TextOutputFormat. The default key/ value separator is a tab character. You can change the separator by setting the property "mapred.textoutputformat.separatorText" in your driver.
您可以使用 TextOutputFormat。默认的键/值分隔符是制表符。您可以通过在驱动程序中设置属性“mapred.textoutputformat.separatorText”来更改分隔符。
conf.set("mapred.textoutputformat.separatorText", ",");