不可能从地图写入到hadoop文件系统(HDFS)
问题描述:
我想直接从mapper在hadoop文件系统中写一个纯文本文件。不可能从地图写入到hadoop文件系统(HDFS)
我做如下:
public void createFile(Configuration conf) throws IOException{
FileSystem fs = FileSystem.get(conf);
Path filenamePath = new Path(conf.get("mapred.output.dir")+"/_"+conf.get("mapred.task.id"), "tree.txt");
try {
if (fs.exists(filenamePath)) {
// remove the file first
fs.delete(filenamePath);
}
FSDataOutputStream out = fs.create(filenamePath);
out.writeUTF("hello, world!");
out.close();
} catch (IOException ioe) {
System.err.println("IOException during operation: " + ioe.toString());
System.exit(1);
}
}
而且它不会写在伪分布式模式什么。然而,在独立写作完美。
问题在哪里?
答
我正在使用Amazon Elastic MapReduce(EMR),我不得不get FileSystem by URI才能够使用S3中的文件。
FileSystem fs = FileSystem.get(uri, conf);
这可能不会帮助你。
你得到的错误是什么?如果传入的'Configuration'对象没有'fs.default.name'属性,它可能会将此文件写入本地磁盘而不是HDFS。 – 2013-03-13 16:56:20
您是否在代码中放置了日志记录并查看日志? – dfrankow 2013-03-13 18:58:38