IT/빅데이터(bigData)

Mapper 클래스 구성 및 사용

까딱이(micropai) 2014. 11. 22. 12:23

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을 상속해서 처리 할 수 있다.