2014-06-19 4 views
0

내 매퍼 구현감속기에서 MapWritable의 순서를 유지하는 방법은 무엇입니까?

public class SimpleMapper extends Mapper<Text, Text, Text, MapWritable> { 

@Override 
protected void map(Text key, Text value,Context context) 
     throws IOException, InterruptedException { 

      MapWritable writable = new LinkedMapWritable(); 
      writable.put("unique_key","one"); 
      writable.put("another_key","two"); 
      context.write(new Text("key"),writable); 
     } 

}

그리고 감속기 구현은 다음과 같습니다

public class SimpleReducer extends Reducer<Text, MapWritable, NullWritable, Text> { 
@Override 
protected void reduce(Text key, Iterable<MapWritable> values,Context context) 
     throws IOException, InterruptedException { 

      // The map writables have to be ordered based on the "unique_key" inserted into it 
     } 

}

내가 차 종류를 사용해야합니까? 그렇게 할 수있는 다른 방법이 있습니까?

답변

1

감속기의 MapWritable (값)은 항상 예측할 수없는 순서이며,이 순서는 실행마다 다를 수 있으며 제어 할 수 없습니다.

그러나지도/축소 패러다임이 보장하는 점은 감속기에 표시된 키가 정렬 된 순서이며 단일 키에 속한 모든 값이 단일 감속기로 이동한다는 것입니다.

따라서 사용 사례에 2 차 정렬 및 사용자 정의 분할을 확실히 사용할 수 있습니다.