2013-07-20 1 views
2

거기에는 시스템 파라미터 (-Dmy_param = XXX와 같은 것)를 어떻게 맵핑 함수에 전달하는 방법이 있나요? hadoop 클러스터에 작업 제출은 .setJarByClass()를 통해 수행됩니다. mapper에서는 구성 파일을 구성해야하므로 configerable로 만들고 싶습니다. 그래서 속성 파일을 통한 표준 방법이 좋을 것이라고 생각했습니다. 속성이 설정된 매개 변수를 전달하는 데 어려움을 겪습니다. 또 다른 방법은 제출 된 jar에 속성 파일을 추가하는 것입니다. 누군가가 그것을 해결하는 방법에 대해 경험이 있습니까?시스템 속성을 hadoop의 맵핑 함수에 전달하는 방법

+0

그래서, 당신은 맵퍼의 각 특성 파일을 전달하려면? –

+0

예. 내가 더 설명하게 해줘. 우리의 맵퍼는 맵 기능으로 구성을 작성해야한다는 것을 의미하는 HBase의 데이터에 액세스합니다. 테스트 등의 목적으로 우리는 하드 코드 된 구성을 갖지 않습니다. 통합 HBase에 대한 더 좋은 방법이 있다면 최선의 접근 방법인지 확신 할 수 없습니다. – jaksky

답변

7

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

참고 : MyDriver는 Configured and implements Tool을 확장합니다. 그리고, 당신 작업, 자세한 내용은 check this link를이

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); 
    } 
} 
+0

코드에서 가져 오기가 누락되었습니다. 링크는 404입니다. Configuration 클래스의 패키지는 무엇입니까? – harschware

관련 문제