2013-11-25 3 views
1

감속기 (텍스트 키와 Iterable MapWritable 값 사용)는 키의 그룹화를 유지하기 위해 모든 맵을 시퀀스 파일로 출력 할 수 있습니까? 예를 들어, 맵퍼의 모습 감속기에 기록을 전송한다고 가정hadoop 시퀀스 파일 콜렉션

<"dog", {<"name", "Fido">, <"pure bred?", "false">, <"type", "mutt">}> 
<"cat", {<"name", "Felix">, <"color", "black">, <"origin", "film">, <"date", "1919">}> 
<"dog", {<"name", "Lassie">, <"type", "collie">, <"origin", " short story">}> 

나는 시퀀스 파일을 원하는만큼 쓸 수 :

key = "dog" 
value = { 
      {<"name", "Fido">, <"pure bred?", "false">, <"type", "mutt">}, 
      {<"name", "Lassie">, <"type", "collie">, <"origin", "short story">} 
     } 

key = "cat" 
value = { 
      {<"name", "Felix">, <"color", "black">, <"origin", "film">, <"date", "1919">} 
     } 

나는이를 만들 필요가 같은데요 Writable을 구현하는 커스텀 값 출력 클래스. 그러나 콜렉션이 시퀀스 파일로는 실제로는 작동하지 않기 때문에 어떻게해야하는지 모르겠습니다. 다음지도/축소 단계에서 각 키와 연결된 모든지도를 단위로 읽을 수 있도록이 작업을 수행하고 싶습니다.

public class MapWritableArray extends ArrayWritable { 
    public MapWritableArray() { 
     super(MapWritable.class); 
    } 
} 

이 그런 다음 감속기에 당신이 배열로 MapWritable 값의 반복자를 축적해야합니다 (: ArrayWritable를 확장

TIA,

당신이 참고로

답변

0

, 당신이 만들 수있는 사용자 정의 쓰기 가능 각 반복마다 기본 내용이 변경됨에 따라 값을 복사하는 것을 기억함). 다음과 같은 것 (완전히 테스트되지 않았으며 검증되지 않고 최적화되지 않음) :

MapWritableArray mapWritableArray = new MapWritableArray(); 
ArrayList<MapWritable> valList = new ArrayList<MapWritable>(); 
for (MapWritable value : values) { 
    MapWritable copy = ReflectionUtils.newInstance(context.getConfiguration(), MapWritable.class); 
    ReflectionUtils.copy(context.getConfiguration, value, copy); 
    valList.add(copy); 
} 
mapWritableArray.set(valList.toArray(new MapWritable[0]));