MapReduce案例学习(9) 将全体员工按照总收入(工资+提成)从高到低排列,要求列出姓名及其总收入

该博客介绍了如何运用MapReduce实现将员工的总收入(工资+提成)从高到低排序,主要改动了employee类的compareTo方法,并在reduce阶段处理输入参数,输出排序后的员工姓名及总收入。
摘要由CSDN通过智能技术生成

设计思路:该题处理方案和MapReduce案例学习(8) 列出工资最高的头三名员工姓名及其工资 类似的,只要将employee类中的compareTo方法改写比较规则即可

map阶段:将employee对象作为key,value直接设置为NullWritable

reduce阶段:在对reduce的输入参数value进行遍历时,里面的对象都是根据key自动排好序的,所以直接把相关信息拼接输出。

package week06;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

/*
 * Employee Object
 */
public class Employee implements WritableComparable<Employee> {
	private String empno;
	private String ename;
	private String job;
	private String mgr;
	private String hiredate;
	private int sal;
	private int comm;
	private String deptno;
	private String dname;
	private String loc;
	private boolean valid = true;

	public void set(Employee emp) {
		this.valid = emp.isValid();
		this.empno = emp.getEmpno();
		this.ename = emp.getEname();
		this.job = emp.getJob();
		this.mgr = emp.getMgr();
		this.hiredate = emp.getHiredate();
		this.sal = emp.getSal();
		this.comm = emp.getComm();
		this.deptno = emp.getDeptno();
		this.dname = emp.getDname();
		this.loc = emp.getLoc();
	}

	//Emp_Test8使用这个compareTo方法
//	 public int compareTo(Employee bean) {
//		 if (this.sal >= bean.getSal()) {
//			 return -1;
//		 } else {
//			 return 1;
//		 }
//	 }

	//Emp_Test9使用这个compareTo方法
	public int compareTo(Employee bean) {
		int total = this.sal + this.comm;
		int bean_total = bean.getSal() + bean.getComm();
		if (total >= bean_total) {
			return -1;
		} else {
			return 1;
		}
	}

	public void write(DataOutput out) throws IOException {
		out.writeUTF(empno);
		out.writeUTF(ename);
		out.writeUTF(job);
		out.writeUTF(mgr);
		out.writeUTF(hiredate);
		out.writeInt(sal);
		out.writeInt(comm);
		out.writeUTF(deptno);
		out.writeUTF(dname);
		out.writeUTF(loc);
		out.writeBoolean(val
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值