//Reduce输出的value值的类型不再是Text,IntWritable,LongWritable类型,这些类型已经不够使用了
需要我们自定义数据类型TVWritable(详细讲解大讲台Hadoop IO讲解)
package com.hadoop.tv;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.WritableComparable;
public class TVWritable implements WritableComparable<Object> {
private long PlayAmount;// 播放数量
private long Collection;// 收藏数量
private long Comment;// 评论数
private long Step;// 获踩数
private long Like;// 获赞
//空参数构造方法
public TVWritable() {
}
//有参数的构造方法
public TVWritable(long playAmount, long collection, long comment,
long step, long like) {
super();
this.PlayAmount = playAmount;
this.Collection = collection;
this.Comment = comment;
this.Step = step;
this.Like = like;
}
public void set(long playAmount, long collection, long comment, long step,
long like) {
this.PlayAmount = playAmount;
this.Collection = collection;
this.Comment = comment;
this.Step = step;
this.Like = like;
}
public long getPlayAmount() {
return PlayAmount;
}
public long getCollection() {
return Collection;
}
public long getComment() {
return Comment;
}
public long getStep() {
return Step;
}
public long getLike() {
return Like;
}
@Override
//readFields是反序列化
public void readFields(DataInput in) throws IOException {
// webSite=in.readInt();
// tvSeries=in.readLine();
PlayAmount = in.readLong();
Collection = in.readLong();
Comment = in.readLong();
Step = in.readLong();
Like = in.readLong();
}
//write是将对象序列化
public void write(DataOutput out) throws IOException {
out.writeLong(PlayAmount);
out.writeLong(Collection);
out.writeLong(Comment);
out.writeLong(Step);
out.writeLong(Like);
}
//如果需要排序就从写该方法
public int compareTo(Object o) {
return 0;
}
}
总结:重点就是序列化和反序列化的两个方法,如果输出需要排序的话可以在compareTo方法中实现