Mapper 와 Reducer (Combiner도 Reducer 를 상속하여 구현한다) 는 job 에 의해

 

내부의 run 메소드가 실행된다.

 

Mapper 의 경우

 public void run(Context context) throws IOException, InterruptedException {

    setup(context);

    try {

      while (context.nextKeyValue()) {

        map(context.getCurrentKey(), context.getCurrentValue(), context);

      }

    } finally {

      cleanup(context);

    }

  }

 

 

위와 같은 로직이 동작하며, mapper 를 상속하여 구현하는 map 이 호출되기 전에 setup 이

완료후에는 cleanup 이 호출되는 것을 확인할 수 있다.

 

setup -> map (해당 datanode 에서 읽은 파일의 라인수 만큼 반복) -> cleanup


즉 이런 식으로 호출된다.

 

즉 initialize 형태의 로직이 필요하다면 setup 을 상속해서

완료이후의 로직이 필요하다면 cleanup을 상속해서 처리 할 수 있다.

'IT > 빅데이터(bigData)' 카테고리의 다른 글

Hive 의 Serde 1  (0) 2014.11.25
MapReduce 데이터 흐름 분석  (0) 2014.11.25
여러 기능의 맵리듀스를 하나의 jar 로 묶을때  (0) 2014.11.22
Hadoop 의 Counter 이야기  (0) 2014.11.22
Reduce 에서 counter 조회  (0) 2014.11.22

 

여러 기능의 맵리듀스를 하나의 jar 로 묶을때 다음과 같이 ProgramDriver 에 해당 class 들을 등록하고

ProgramDriver  에 각 클래스를 등록한 class 를 jar 의 main 클래스로 잡아서 jar 로 압축한다.

 

실행시 해당 jar 에 등록된 alias 로 실행한다.

$ hadoop jar analyserDriver.jar max   < 기타 max 에서 구현된 파라미터 >

 

 public class AnalyserDriver {

 

   public static void main(String argv[]) {

     int exitCode = -1;

     ProgramDriver programDriver = new ProgramDriver();

     try {

          programDriver.addClass("standarddeviation", StandardDeviationDriver.class, 

                "A map/reduce program that calculate the standarddeviation in the input files.");

 programDriver.addClass("mode", ModeDriver.class, 

                "A map/reduce program that calculates the mode in the input files.");

programDriver.addClass("max", Max.class, 

  "A map/reduce program that max the total row in the input files.");

          programDriver.addClass("min", Min.class, 

                "A map/reduce program that min the total row in the input files.");

          programDriver.addClass("median", Median.class,

                "A map/reduce program that median the total row in the input files.");

        exitCode = programDriver.run(argv); 

    } catch (Throwable e) {

          e.printStackTrace();

    }

    System.exit(exitCode);

  }

}

 

 

'IT > 빅데이터(bigData)' 카테고리의 다른 글

MapReduce 데이터 흐름 분석  (0) 2014.11.25
Mapper 클래스 구성 및 사용  (0) 2014.11.22
Hadoop 의 Counter 이야기  (0) 2014.11.22
Reduce 에서 counter 조회  (0) 2014.11.22
hadoop counter 사용  (0) 2014.11.21

+ Recent posts