【发布时间】:2015-03-02 23:50:18
【问题描述】:
我正在对一些网络数据进行 MapReduces。 (我是 MapReduce 新手,所以想想经典的 WordCount 类型的东西。)输入文件如下,数字后跟一个制表符:
3 2 2 4 2 2 2 3 3
虽然我了解如何获得数字的经典“字数”,但我真正想做的是成对评估数字,因此映射器会将上述内容读取为 '3 2', '2 2 '、'2 4'、'2 2' 等等。我该怎么做呢?我想所有必要的就是调整 StringTokenizer 以按第二个选项卡或其他东西拆分单词,但我该怎么做呢?这甚至可能吗?
这是我正在使用的 Java 代码,到目前为止,它只是 MapReduce 中的经典 WordCount 示例:
public static class TokenizerMapper
extends Mapper<Object, Text, Text, IntWritable>{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}
【问题讨论】:
标签: java string hadoop mapreduce