自定义MapReduce的类型
package org.apache.hadoop.mapreduce.io; import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException; import org.apache.hadoop.io.WritableComparable; /***
* customize writable eg.order
*
* @author nele
*
*/
public class OrderWritable implements WritableComparable<OrderWritable> { private String orderId; private float price; public OrderWritable() {
} public OrderWritable(String orderId, float price) {
set(orderId, price);
} public void set(String orderId, float price) {
this.orderId = orderId;
this.price = price;
} public String getOrderId() {
return orderId;
} public void setOrderId(String orderId) {
this.orderId = orderId;
} public float getPrice() {
return price;
} public void setPrice(float price) {
this.price = price;
} public void write(DataOutput out) throws IOException {
out.writeUTF(orderId);
out.writeFloat(price);
} public void readFields(DataInput in) throws IOException {
this.orderId = in.readUTF();
this.price = in.readFloat();
} public int compareTo(OrderWritable o) {
int comp = this.orderId.compareTo(o.orderId);
if (comp == 0) {
return Float.valueOf(this.price).compareTo(Float.valueOf(o.price));
}
return comp;
} @Override
public String toString() {
return orderId + "\t" + price;
} @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((orderId == null) ? 0 : orderId.hashCode());
result = prime * result + Float.floatToIntBits(price);
return result;
} @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OrderWritable other = (OrderWritable) obj;
if (orderId == null) {
if (other.orderId != null)
return false;
} else if (!orderId.equals(other.orderId))
return false;
if (Float.floatToIntBits(price) != Float.floatToIntBits(other.price))
return false;
return true;
} }
这样就可以,在mapreduce中使用。
需要根据具体的情境具体的设计。
自定义MapReduce的类型的更多相关文章
- MapReduce的类型与格式
MapReduce的类型 默认的MR作业 默认的mapper是Mapper类,它将输入的键和值原封不动地写到输出中 默认的partitioner是HashPartitioner,它对每条记录的键进行哈 ...
- typedef和自定义结构体类型
在自定义结构体类型时会用到typedef关键字.大家都知道typedef是取别名的意思,在C语言中跟它容易混淆的有const,#define等,其区别不在本篇文章讨论之列. /*定义单链表结点类型*/ ...
- iOS回顾笔记(08) -- 自定义Cell的类型和创建步骤总结
iOS回顾笔记(08) -- 自定义Cell的类型和创建步骤总结 项目中我们常见的自定义cell主要分为两种 等高cell:如应用列表.功能列表 非等高cell:如微博列表.QQ聊天页面 下面对这 ...
- ORM中自定义一个char类型字段
自定义一个char类型字段 class MyCharField(models.Field): """ 自定义的char类型的字段类 """ ...
- MyBatis使用自定义TypeHandler转换类型的实现方法
From: http://www.manongjc.com/article/15577.html 这篇文章主要介绍了MyBatis使用自定义TypeHandler转换类型的实现方法,本文介绍使用Typ ...
- MyBatis使用自定义TypeHandler转换类型
MyBatis虽然有很好的SQL执行性能,但毕竟不是完整的ORM框架,不同的数据库之间SQL执行还是有差异. 笔者最近在升级 Oracle 驱动至 ojdbc 7 ,就发现了处理DATE类型存在问题. ...
- [转]在Storyboard中使用自定义的segue类型
转自:http://my.oschina.net/u/728866/blog/92709 我们知道segue共有三种类型:push.modal以及custom.如下图: 很明显,这三种类型的作用分 ...
- map自定义键值类型
map自定义键值类型 改变Map的默认比较方式 https://www.cnblogs.com/zjfdlut/archive/2011/08/12/2135698.html 大家知道,STL中的ma ...
- mapreduce 输入输出类型
默认的mapper是IdentityMapper,默认的reducer是IdentityReducer,它们将输入的键和值原封不动地写到输出中. 默认的partitioner是HashPartitin ...
随机推荐
- BZOJ1010 [HNOI2008]玩具装箱toy
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...
- FUSE 简介
编译别人改过的一个 OpenWRT ,发现用到了一个叫 FUSE 的包.感兴趣了解一下. FUSE 是 Filesystem in USErspace 的简称.对于文件系统,经常安装系统.格式化 U ...
- 用python虚拟串口
在linux下调试串口程序,无奈下面的硬件还没到位,所以,想着自己模拟一个串口用用.试了下下面这段代码: #!/usr/bin/env python #coding=utf-8 import pty ...
- 数据结构与算法分析 - 最大公约数(gcd & extended_gcd)
以下内容均节选自<算法导论>第31章 最大公约数 定义:若:\[\begin{array}{l}a = p_1^{e_1}p_2^{e_2} \ldots p_r^{e_r}\\b = p ...
- 和redis谈一场恋爱(第二天约会了解彼此)
最近使用了Memcache,带来的便利已经让我欣喜若狂.开启了另一种又快又好的方式存储和读取数据.中间经过了一番折腾,学习了mysql,终于有学到了redis. Redis的全名是Remote Dic ...
- 超强语感训练文章(Provided by Rocky teacher Prince)
Content: Class1 My name is Prince Class2 Welcome to our hotel Class3 We’re not afraid of problems Cl ...
- POJ3612:Telephone Wire
传送门 一道很棒的DP题目. 裸的DP方程很好搞: $f[i][j]=min \{ f[i-1][k]+ C \times |k-j| +(k-a[i])^2 \}$ 这个复杂度显然无法承受,考虑优化 ...
- Saltstack之Syndic(十)
Saltstack之Syndic 使用条件: 1.salt syndic必须运行在一台master上 2.salt syndic必须依赖更高级的master 安装 yum install -y sal ...
- linux安装ftp组件
1 安装vsftpd组件 linux系统安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件. [root@bogon ~]# yum -y install v ...
- AppleHDA 10.9.3 disassm 1
1.通过AppleHDAFunctionGroupFactory::createAppleHDAFunctionGroup(DevIdStruct *)实际创建相应的 AppleHDAFunction ...