【发布时间】:2013-11-18 09:21:51
【问题描述】:
我有一个要在 MapReduce 作业中处理的 XML 文件。虽然我可以在未压缩时处理它,但当我将其压缩为 bz2 格式并将其存储在 hdfs 中时它不起作用。我是否需要进行一些更改,例如指定要使用的编解码器 - 我不知道在哪里做。任何例子都会很棒。我正在使用来自 mahaout 的 XMLInputFormat 来读取未压缩的 XML 文件。我使用bzip2 命令压缩文件并使用hadoop dfs -copyFromLocal 将文件复制到DFS。我有兴趣阅读和处理 xml 文档的 <page></page> 标记内的内容。我正在使用 hadoop-1.2.1 发行版。我可以看到有 FileOutputFormat.setOutputCompressorClass,但 FileInputFormat 没有类似的东西。
这是我工作的 Main 课程。
public class Main extends Configured implements Tool {
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new Main(), args);
System.exit(res);
}
public int run(String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: hadoop jar XMLReaderMapRed "
+ " [generic options] <in> <out>");
System.out.println();
ToolRunner.printGenericCommandUsage(System.err);
return 1;
}
Job job = new Job(getConf(), "XMLTest");
job.setInputFormatClass(MyXMLInputFormat.class);
//Specify the start and end tag that has content
getConf().set(MyXMLInputFormat.START_TAG_KEY, "<page>");
getConf().set(MyXMLInputFormat.END_TAG_KEY, "</page>");
job.setJarByClass(getClass());
job.setMapperClass(XMLReaderMapper.class);
job.setReducerClass(XmlReaderReducer.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
boolean success = job.waitForCompletion(true);
return success ? 0 : 1;
}
}
编辑:Reading from Hadoop - The Definitive Guide by Tom White,提到“如果您的输入文件被压缩,它们将在被 mapReduce 读取时自动解压缩,使用文件扩展名来确定要使用的编解码器。”所以文件是自动解压的,但是为什么输出目录会创建一个空文件呢?
谢谢!
【问题讨论】: