java—如何在hadoop中将mapoutputvalueclass设置为枚举

c6ubokkw  于 2021-06-01  发布在  Hadoop
关注(0)|答案(0)|浏览(191)

我的Map器输出值是enum的一种类型,我将maputValueClass设置为enum.class,但总是得到 Type mismatch in value from map expected StatisticTypes, recieved StatisticTypes$2 似乎它收到的是嵌套类而不是子类,我的枚举类有什么问题吗?
作业设置:

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);
}

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题