【发布时间】:2017-04-30 13:11:09
【问题描述】:
我是 map reduce 的新手,遇到 NoSuchElementException,请帮忙。
在文本下方输入文件容器:
this is a hadoop program
i am writing it for first time
映射器类:
public class Mappers extends MapReduceBase implements Mapper<LongWritable, Text, IntWritable, IntWritable>{
private Text word = new Text();
private IntWritable singleWordCount = new IntWritable();
private IntWritable one = new IntWritable(1);
@Override
public void map(LongWritable key, Text value, OutputCollector<IntWritable, IntWritable> output, Reporter reporter) throws IOException {
StringTokenizer wordList = new StringTokenizer(value.toString());
while (wordList.hasMoreTokens()) {
int wordSize = wordList.nextToken().length();
singleWordCount.set(wordSize);
if(word != null && wordList != null && wordList.nextToken() != null){
word.set(wordList.nextToken());
output.collect(singleWordCount, one);
}
}
}
}
【问题讨论】:
标签: hadoop mapreduce stringtokenizer