2017-02-07 4 views
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); 
} 
} 

이 단지 목적을 학습 그래서 난 정말 당신의 도움을 주셔서 감사합니다 것입니다 응용 프로그램에 대한 사용하고있는 코드입니다!

고맙습니다.

답변

2

하둡은 이미지도 메소드 호출 수를 계산합니다. 당신은 카운터에서 응용 프로그램의 UI에서 볼 섹션 또는이 끝난 후 직장에서 얻을 수 있습니다 :

int code = job.waitForCompletion(true) ? 0 : 1; 

String group = "Map-Reduce Framework"; 
String counter = "Map input records"; 

long val = job.getCounters().getGroup(group).findCounter(counter).getValue(); 

투기 실행이 활성화 된 경우이 숫자가 입력 파일 라인의 수보다 더 클 수 있다는 것을 기억하십시오.

+0

그래서이 코드를 내 메인 메소드에 추가해야합니까? @AdamSkywalker – useruser1412

+0

@ useruser1412 예 – AdamSkywalker