본문 바로가기
Hadoop

Hadoop Writable

by 언덕너머에 2014. 7. 2.

- Writarble
DataInput 과 DataOutput 인터페이스를 기반으로 간단하고 효율적으로 serialization protocol을 
구현하는 serializable object이다. 
하둡 Map-Reduce Framework 안에서 모든 key나 value Type은 이 인터페이스를 구현한다.
일반적인 구현은 readFields를 호출하고 해당 인스턴스를 반환하는 새로운 인스턴스를 생성하는 
메소드 static read(DataInput)를 구현한다. 

     public class MyWritable implements Writable {
       // Some data     
       private int counter;
       private long timestamp;

       //out으로 Object의  fields를 Serialize한다.
       public void write(DataOutput out) throws IOException {
         out.writeInt(counter);
         out.writeLong(timestamp);
       }
       
       //in 으로부터 object의 fields로  deserialize한다.
       public void readFields(DataInput in) throws IOException {
         counter = in.readInt();
         timestamp = in.readLong();
       }
       
       public static MyWritable read(DataInput in) throws IOException {
         MyWritable w = new MyWritable();
         w.readFields(in);
         return w;
       }
     }

'Hadoop' 카테고리의 다른 글

Hadoop OutputCollector  (0) 2014.06.27
Hadoop setPartitionerClass & setGroupingComparatorClass  (0) 2014.06.16
Hadoop Chain  (0) 2014.06.16
Hadoop Output Format  (0) 2014.06.13
Reducer  (0) 2014.06.09