복붙노트

[HADOOP] hadoop에서 enum으로 mapOutputValueClass를 설정하는 방법

HADOOP

hadoop에서 enum으로 mapOutputValueClass를 설정하는 방법

내 매퍼 출력 값은 Enum의 한 유형이며, MapOutputValueClass를 Enum.class로 설정하지만 항상 가져옵니다. 예상지도에서 값 유형이 일치하지 않습니다. StatisticTypes, received StatisticTypes $ 2

하위 클래스 대신 중첩 된 클래스를받은 것처럼 보입니다. Enum 클래스에 문제가 있습니까?

작업 설정 :

job.setMapOutputValueClass(StatisticTypes.class);

산출:

for(StatisticTypes statistic : dimensionCountMap.get(key)) {
    context.write(key, statistic);
}

열거 형 :

public enum StatisticTypes implements Writable{
MAX {
    @Override
    public boolean aggregate(long v, LongWritable userId) {
        if (v > value) {
            value = v;
            this.userId = userId;
            return true;
        }
        return false;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        ObjectWritable objWritable = new ObjectWritable(this);
        objWritable.write(out);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        ObjectWritable objWritable = new ObjectWritable();
        objWritable.readFields(in);
    }
};
public LongWritable userId;
public long value;
public abstract boolean aggregate(long v, LongWritable userId);
public long getValue() {
    return value;
};
public LongWritable getUserId() {
    return userId;
}
@Override
public void write(DataOutput out) throws IOException {
    ObjectWritable objWritable = new ObjectWritable(this);
    objWritable.write(out);
}

@Override
public void readFields(DataInput in) throws IOException {
    ObjectWritable objWritable = new ObjectWritable();
    objWritable.readFields(in);
}

}

해결법

    from https://stackoverflow.com/questions/49369532/how-to-set-mapoutputvalueclass-as-enum-in-hadoop by cc-by-sa and MIT license