복붙노트

[HADOOP] hadoop에서 시스템 속성을 맵 함수에 전달하는 방법

HADOOP

hadoop에서 시스템 속성을 맵 함수에 전달하는 방법

hadoop map reduce 프레임 워크에서 시스템 매개 변수 (-Dmy_param = XXX와 같은 것)를 맵 함수에 전달하는 방법이 있습니까? hadoop 클러스터에 대한 작업 제출은 .setJarByClass ()를 통해 수행됩니다. 매퍼에서 구성을 작성해야 구성 할 수 있기를 원하므로 속성 파일을 통한 표준 방법은 괜찮을 것이라고 생각했습니다. 속성이 설정된 곳에 매개 변수를 전달하는 데 어려움을 겪고 있습니다. 다른 방법은 제출 된 jar에 특성 파일을 추가하는 것입니다. 누군가가 어떻게 그것을 해결 한 경험이 있습니까?

해결법

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

    1.작업에서 아직 이것을 사용하지 않은 경우 Hadoop 작업을 실행하기 위해 GenericOptionsParser, Tool 및 ToolRunner를 시도 할 수 있습니다.

    작업에서 아직 이것을 사용하지 않은 경우 Hadoop 작업을 실행하기 위해 GenericOptionsParser, Tool 및 ToolRunner를 시도 할 수 있습니다.

    참고 : MyDriver는 구성을 확장하고 도구를 구현합니다. 그리고, 당신이 일을 실행하려면 이것을 사용하십시오

    hadoop -jar somename.jar MyDriver -D your.property=value arg1 arg2
    

    자세한 내용은이 링크를 확인하십시오.

    다음은 내가 준비한 샘플 코드입니다.

    public class MyDriver extends Configured implements Tool {
    
      public static class MyDriverMapper extends Mapper<LongWritable, Text, LongWritable, NullWritable> {
    
        protected void map(LongWritable key, Text value, Context context)
          throws IOException, InterruptedException {
          // In the mapper you can retrieve any configuration you've set
          // while starting the job from the terminal as shown below
    
          Configuration conf = context.getConfiguration();
          String yourPropertyValue = conf.get("your.property");
        }
      }
    
      public static class MyDriverReducer extends Reducer<LongWritable, NullWritable, LongWritable, NullWritable> {
    
        protected void reduce(LongWritable key, Iterable<NullWritable> values, Context context) 
          throws IOException, InterruptedException {
          // --- some code ---
        }
      }
    
      public static void main(String[] args) throws Exception {
        int exitCode = ToolRunner.run(new MyDriver(), args);
        System.exit(exitCode);
      }
    
      @Override
      public int run(String[] args) throws Exception {
        Configuration conf = getConf();
        // if you want you can get/set to conf here too.
        // your.property can also be file location and after
        // you retrieve the properties and set them one by one to conf object.
    
        // --other code--//
        Job job = new Job(conf, "My Sample Job");
        // --- other code ---//
        return (job.waitForCompletion(true) ? 0 : 1);
      }
    }
    
  2. from https://stackoverflow.com/questions/17759826/how-to-pass-system-property-to-map-function-in-hadoop by cc-by-sa and MIT license