복붙노트

[HADOOP] Hadoop에서 List 컬렉션 객체를 직렬화하는 방법은 무엇입니까?

HADOOP

Hadoop에서 List 컬렉션 객체를 직렬화하는 방법은 무엇입니까?

Hadoop에서 Java 컬렉션을 직렬화하는 방법이 있습니까?

쓰기 가능 인터페이스는 Java 프리미티브 전용입니다. 다음과 같은 클래스 속성이 있습니다.

private String keywords;
private List<Status> tweets;
private long queryTime = 0;

public TweetStatus(String keys, List<Status> tweets, long queryTime){
    this.keywords = keys;
    this.tweets = tweets;
    this.queryTime = queryTime;
}

List 객체를 직렬화하는 방법은 무엇입니까?

해결법

  1. ==============================

    1.권리. 기본적으로 객체를 일련화할 수있는 일련의 객체로 분해해야합니다.

    권리. 기본적으로 객체를 일련화할 수있는 일련의 객체로 분해해야합니다.

    따라서 첫 번째 원칙에서 목록을 직렬화하려면 목록의 크기를 직렬화 한 다음 목록의 각 요소를 직렬화해야합니다. 이렇게하면 역 직렬화가 필요한 경우 역 직렬화해야하는 요소 수를 알 수 있습니다.

    이와 같은 것이 쓰기 (pun!) 트랙에 있어야합니다.

    class TweetStatusWritable implements Writable {
        private String keywords;
        private List<Status> tweets;
        private long queryTime;
    
        // add getters for the above three fields
    
        public void readFields(DataInput in) {
            this.keywords = in.readUTF();
            int size = in.readInt();
            this.tweets = new List<Status>();
            for(int i = 0; i < size; i++) {
                Status status = // deserialize an instance of Status
                tweets.add(status);
            }
            this.queryTime = in.readLong();
        }
    
        public void write(DataOutput out) {
            out.writeUTF(this.keywords);
            out.writeInt(this.tweets.size());
            for(int i = 0; i < this.tweets.size(); i++) {
                 // serialize tweets[i] onto out
            }       
            out.writeLong(queryTime);
        }
    
        public TweetStatusWritable(
            String keywords,
            List<Status> tweets,
            long queryTime
        ) {
            this.keywords = keywords;
            this.tweets = tweets;
            this.queryTime = queryTime;
        }
    }
    
  2. ==============================

    2.ArrayWritable을 살펴보십시오. 인스턴스 배열을 모두 직렬화 할 수 있습니다 (모두 동일한 유형). 당신은 당신의 목록에서 그 중 하나를 구축 할 수 있습니다

    ArrayWritable을 살펴보십시오. 인스턴스 배열을 모두 직렬화 할 수 있습니다 (모두 동일한 유형). 당신은 당신의 목록에서 그 중 하나를 구축 할 수 있습니다

  3. ==============================

    3.많은 직렬화 항목이 있다면 Avro가 유용 할 수 있습니다.

    많은 직렬화 항목이 있다면 Avro가 유용 할 수 있습니다.

  4. from https://stackoverflow.com/questions/17220884/how-to-serialize-list-collection-object-in-hadoop by cc-by-sa and MIT license