【发布时间】:2019-02-24 00:44:57
【问题描述】:
我正在尝试实现一个 map reduce 程序,以便输出是 .txt 文件的对角线。 例如,读取文件
a*****
*b****
**c***
***d**
****e*
*****f
我希望输出为 abcdef。
我写的映射器类是这个:
public class MapperClass extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text>
{
//hadoop supported data types
private static final Text t = new Text("");
private Text word = new Text();
//private static int linenumber = 0;
public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException
{
//taking one line at a time from input file
String line = value.toString();
int linenumber = 0;
word.set(Character.toString(line.charAt(linenumber++)));
output.collect(word, t);
}
}
但我得到的输出是
a
*
*
*
*
*
我尝试将行号从 map 方法中删除,但仍然得到相同的结果。有人可以帮忙吗?我只需要找到一种方法来保持计数器在我从文件中读取下一行时递增。 P.S. 我认为这里不需要减速器,因为我不想对任何中间结果进行排序。如果我错了,请纠正我。 谢谢!
【问题讨论】: