开发者学堂课程【Hadoop 分布式计算框架 MapReduc:ReduceJoin 案例 TableBean】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/94/detail/1546
ReduceJoin 案例 TableBean
代码示例
创建商品和订合并后的 Bean 类
package com.liun.mr.reducejoin;
import java.io.DataInput; import java.io.DataOutput; import java.io.IOException;
import org.apache.hadoop.io.Writable;
public class TableBean implements Writable{
private String order_id; private String p_id; private int amount; private String pname; private String flag; public TableBean() { super(); }
public TableBean(String order_id, String p_id, int amount, String pname, String flag) { super(); this.order_id = order_id; this.p_id = p_id; this.amount = amount; this.pname = pname; this.flag = flag; }
@Override public void write(DataOutput out) throws IOException { // 序列化 out.writeUTF(order_id); out.writeUTF(p_id); out.writeInt(amount);; out.writeUTF(pname); out.writeUTF(flag); }
@Override public void readFields(DataInput in) throws IOException { // 反序列化 order_id = in.readUTF(); p_id = in.readUTF(); amount = in.readInt(); pname = in.readUTF(); flag = in.readUTF(); }
public String getOrder_id() { return order_id; }
public void setOrder_id(String order_id) { this.order_id = order_id; }
public String getP_id() { return p_id; }
public void setP_id(String p_id) { this.p_id = p_id; }
public int getAmount() { return amount; }
public void setAmount(int amount) { this.amount = amount; }
public String getPname() { return pname; }
public void setPname(String pname) { this.pname = pname; }
public String getFlag() { return flag; }
public void setFlag(String flag) { this.flag = flag; }
@Override public String toString() { return order_id + "\t" + amount + "\t" + pname; } } |