복붙노트

[HADOOP] Hadoop : 매퍼 출력을 출력 파일에 작성하는 감속기

HADOOP

Hadoop : 매퍼 출력을 출력 파일에 작성하는 감속기

나는 매우 이상한 문제를 만났다. 감속기가 작동하지만 출력 파일을 검사하면 매퍼의 출력 만 발견됩니다. 디버깅을 시도 할 때 mappers의 출력 값 유형을 Longwritable에서 Text로 변경 한 후 단어 개수 샘플에서 같은 문제가 발견되었습니다.

    package org.myorg;

import java.io.IOException;
import java.util.*;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.*;
import org.apache.hadoop.mapreduce.lib.output.*;
import org.apache.hadoop.util.*;

public class WordCount extends Configured implements Tool {

   public static class Map
       extends Mapper<LongWritable, Text, Text, Text> {
     private final static IntWritable one = new IntWritable(1);
     private Text word = new Text();

     public void map(LongWritable key, Text wtf, Context context)
         throws IOException, InterruptedException {
       String line = wtf.toString();
       StringTokenizer tokenizer = new StringTokenizer(line);
       while (tokenizer.hasMoreTokens()) {
         word.set(tokenizer.nextToken());
         context.write(word, new Text("frommapper"));
       }
     }
   }

   public static class Reduce
       extends Reducer<Text, Text, Text, Text> {
     public void reduce(Text key, Text wtfs,
         Context context) throws IOException, InterruptedException {
/*
       int sum = 0;
       for (IntWritable val : wtfs) {
         sum += val.get();
       }
       context.write(key, new IntWritable(sum));*/
    context.write(key,new Text("can't output"));
     }
   }

   public int run(String [] args) throws Exception {
     Job job = new Job(getConf());
     job.setJarByClass(WordCount.class);
     job.setJobName("wordcount");


     job.setOutputKeyClass(Text.class);
     job.setMapOutputValueClass(Text.class);
       job.setOutputValueClass(Text.class);
     job.setMapperClass(Map.class);
     //job.setCombinerClass(Reduce.class);
     job.setReducerClass(Reduce.class);

     job.setInputFormatClass(TextInputFormat.class);
     job.setOutputFormatClass(TextOutputFormat.class);

     FileInputFormat.setInputPaths(job, new Path(args[0]));
     FileOutputFormat.setOutputPath(job, new Path(args[1]));

     boolean success = job.waitForCompletion(true);
     return success ? 0 : 1;
         }

   public static void main(String[] args) throws Exception {
     int ret = ToolRunner.run(new WordCount(), args);
     System.exit(ret);
   }
}

여기에 결과가있다.

JobClient:     Combine output records=0
12/06/13 17:37:46 INFO mapred.JobClient:     Map input records=7
12/06/13 17:37:46 INFO mapred.JobClient:     Reduce shuffle bytes=116
12/06/13 17:37:46 INFO mapred.JobClient:     Reduce output records=7
12/06/13 17:37:46 INFO mapred.JobClient:     Spilled Records=14
12/06/13 17:37:46 INFO mapred.JobClient:     Map output bytes=96
12/06/13 17:37:46 INFO mapred.JobClient:     Combine input records=0
12/06/13 17:37:46 INFO mapred.JobClient:     Map output records=7
12/06/13 17:37:46 INFO mapred.JobClient:     Reduce input records=7

outfile에서 이상한 결과를 발견했습니다. 이 문제는 감소 출력 값의 유형을 변경했는지 여부에 관계없이 맵의 출력 값 유형을 감속기의 입력 키 유형을 텍스트로 변경 한 후에 발생합니다. 나는 또한 job.setOutputValue (Text.class)를 강제로 변경해야했다.

a   frommapper
a   frommapper
a   frommapper
gg  frommapper
h   frommapper
sss frommapper
sss frommapper

도움!

해결법

  1. ==============================

    1.reduce 함수 인자는 다음과 같아야합니다 :

    reduce 함수 인자는 다음과 같아야합니다 :

    public void reduce(Text key, Iterable <Text> wtfs,
         Context context) throws IOException, InterruptedException {
    

    인수를 정의한 방식으로 reduce 연산은 값 목록을 얻지 못하기 때문에 map 함수에서 가져온 입력을 출력합니다.

    sum+ = val.get()
    

    형식의 각 쌍이 감속기에 별도로 제공되므로 매번 0에서 1로 갈 것입니다.

    또한 매퍼 함수는 일반적으로 출력 파일에 쓰지 않습니다 (필자는 들어 본 적이 없지만 가능하면 알 수 없습니다). 일반적인 경우 출력 파일에 기록하는 것이 항상 감속기입니다. Mapper 출력은 Hadoop이 투명하게 처리하는 중간 데이터입니다. 따라서 출력 파일에서 무언가를 볼 수 있다면 출력은 매퍼 출력이 아니라 감속기 출력이어야합니다. 이를 확인하려면 실행 한 작업의 로그로 이동하여 각 매퍼 및 축소 기에서 일어나는 일을 개별적으로 확인하십시오.

    희망이 당신을 위해 몇 가지를 지 웁니다.

  2. from https://stackoverflow.com/questions/11025390/hadoop-reducer-writing-mapper-output-into-output-file by cc-by-sa and MIT license