我有一个目录OUTPUT,其中有来自Map Reduce作业的输出文件。输出文件是使用TextOutputFormat编写的文本文件。Hadoop中的文本阅读器类
现在我想从输出文件中读取键值对。我如何使用hadoop中的一些现有类来做到这一点。我可以做的一种方法是如下
FileSystem fs = FileSystem.get(conf);
FileStatus[] files = fs.globStatus(new Path(OUTPUT + "/part-*"));
for(FileStatus file:files){
if(file.getLen() > 0){
FSDataInputStream in = fs.open(file.getPath());
BufferedReader bin = new BufferedReader(new InputStreamReader(
in));
String s = bin.readLine();
while(s!=null){
System.out.println(s);
s = bin.readLine();
}
in.close();
}
}
这种做法会工作,但增加了我的任务很大,因为我现在需要手动解析键值对出每根线的。我正在寻找更方便的东西,直接让我读取一些变量中的键和值。
下面是hadoop中读者类的列表 - http://www.buggybread.com/2015/09/apache-hadoop-list-of-reader-classes.html。这可能有帮助。 –