0
MapReduce WordCount 샘플 응용 프로그램을 사용하여지도 단계에서 Map 메서드가 호출 된 횟수를 출력하도록 코드를 편집하고 싶습니다. . 나는 두 개의 텍스트 파일이이 내가MapReduce의지도 단계에서 시작된지도 메서드 수 찾기 단어 수 예
public class 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);
}
}
}
public static class IntSumReducer
extends Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values,
Context context
) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
이 단지 목적을 학습 그래서 난 정말 당신의 도움을 주셔서 감사합니다 것입니다 응용 프로그램에 대한 사용하고있는 코드입니다!
고맙습니다.
그래서이 코드를 내 메인 메소드에 추가해야합니까? @AdamSkywalker – useruser1412
@ useruser1412 예 – AdamSkywalker