MapReduce에서 감속기를 확장하는 정적 내부 클래스의 정적 변수에 액세스하는 방법은 무엇입니까?

구유

내 프로그램의 주요 방법 코드는 다음과 같습니다.

public class Path {
public static void main(String[] args) throws Exception {
    ArrayList<String> input = new ArrayList<String> ();
    input.add(args[0]);
    String output0="/output/path2";

    Route r1 =new Route(input,output0,2);
    r1.main(args);
    input.add(output0);
    String output1="/output/path3";

    Route r2 =new Route(input,output1,3);
    r2.main(args);
}}

클래스 경로에는 정적 내부 클래스가 매퍼를 확장하고 정적 내부 클래스가 감속기를 확장합니다. 다음은 내 질문과 관련된 클래스 경로 정의의 일부입니다.

public class Route {
public static int len;
public static String output;
public static ArrayList<String> input = new ArrayList<String> ();

public static class RouteMapper extends Mapper<Object, Text, Text, Text> {
    public void map(Object key,Text value,Context context) throws IOException,InterruptedException {
       //do map
    }
}

public static class RouteReducer extends Reducer<Text, Text, Text, Text> {
    public void reduce(Text key, Iterable<Text> values, Context context) throws IOException,InterruptedException{
       //do reduce
    }
}

public Route(ArrayList<String> in,String out,int l){
    len = l;
    output = out;
    Iterator itr = in.iterator();
    while(itr.hasNext()){
        input.add(itr.next().toString());
    }
}

public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    //some configs of mapreduce
}}

내 주요 방법에서 볼 수 있듯이 정적 변수 len의 값은 두 개의 맵 / 축소 구문에서 2와 3이어야합니다. 그러나 축소 구문에서 len 값을 컨텍스트에 쓰려고 할 때 변수 len의 기본값 인 0 값을 얻었습니다.
그 때문에 원하는대로 정확한 결과를 얻을 수 없습니다. 내부 정적 클래스 RouteReducer가 외부 클래스 Route의 정적 변수에 액세스 할 수없는 이유를 매우 혼란스럽게합니다.

삑 하는 소리

Hadoop은 분산 시스템입니다. 매퍼 및 리듀서 구현의 컴파일 된 클래스는 자체 JVM에서 작동하는 다른 노드로 복사됩니다. 따라서 기본 클래스와 각 작업은 동일한 변수의 다른 인스턴스를 봅니다. 메인 클래스에서 작업으로 데이터를 수동으로 전달해야합니다.

경량 데이터는 다음을 통해 메인 클래스에서 작업을 매핑하고 줄일 수 있습니다 Configuration.

// in main
public static final String CONF_LEN = "conf.len";
...
conf.setInt(CONF_LEN, 3);

// in mapper
@Override
protected void setup(Mapper<Object, Text, Text, Text>.Context context) throws IOException, InterruptedException {
  super.setup(context);
  this.len = context.getConfiguration().getInt(CONF_LEN, -1);
}

대용량 데이터는 분산 캐시를 통해 전송 될 수 있습니다 .

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관