【Hbase学习之五】HBase MapReduce
环境
虚拟机:VMware 10
Linux版本:CentOS-6.5-x86_64
客户端:Xshell4
FTP:Xftp4
jdk8
hadoop-2.6.5
hbase-0.98.12.1-hadoop2
package wc; import java.io.IOException;
import java.util.StringTokenizer; import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper; public class WCMapper extends Mapper<LongWritable, Text, Text, IntWritable> { @Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String[] strs = value.toString().split(" ");
for (String string : strs) {
context.write(new Text(string), new IntWritable(1));
}
}
}
package wc; import java.io.IOException; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text; public class WCReducer extends TableReducer<Text, IntWritable, ImmutableBytesWritable> { @Override
protected void reduce(Text text, Iterable<IntWritable> iterable, Context context)
throws IOException, InterruptedException { int sum = 0;
for (IntWritable it : iterable) {
sum += it.get();
}
//将mr结果输出到HBase
Put put = new Put(text.toString().getBytes());
put.add("cf".getBytes(), "ct".getBytes(), (sum + "").getBytes());
context.write(null, put); }
}
package wc; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; public class WCRunner { public static void main(String[] args) throws Exception { Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://node1:8020");
conf.set("hbase.zookeeper.quorum", "node1,node2,node3");
Job job = Job.getInstance(conf);
job.setJarByClass(WCRunner.class); // 指定mapper 和 reducer
job.setMapperClass(WCMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
// 最后一个参数设置false
// adddependecyjars=false 表示不将jar上传分布式集群 即 本地执行
TableMapReduceUtil.initTableReducerJob("wc", WCReducer.class, job, null, null, null, null, false);
FileInputFormat.addInputPath(job, new Path("/user/hive/warehouse/wc/"));
job.waitForCompletion(true);
}
}
【Hbase学习之五】HBase MapReduce的更多相关文章
- Hbase 学习(一) hbase配置文件同步
最近在狂啃hadoop的书籍,这部<hbase:权威指南>就进入我的视野里面了,啃吧,因为是英文的书籍,有些个人理解不对的地方,欢迎各位拍砖. HDFS和Hbase配置同步 hbase的配 ...
- HBase 学习之一 <<HBase使用客户端API动态创建Hbase数据表并在Hbase下导出执行>>
HBase使用客户端API动态创建Hbase数据表并在Hbase下导出执行 ----首先感谢网络能够给我提供一个开放的学习平台,如果没有网上的技术爱好者提供 ...
- HBase学习——3.HBase表设计
1.建表高级属性 建表过程中常用的shell命令 1.1 BLOOMFILTER 默认是 NONE 是否使用布隆过虑及使用何种方式,布隆过滤可以每列族单独启用 使用HColumnDescriptor. ...
- HBase学习笔记-HBase性能研究(1)
使用Java API与HBase集群交互时,需要构建HTable对象,使用该对象提供的方法来进行插入/删除/查询等操作.要创建HTable对象,首先要创建一个带有HBase集群信息的配置对象Confi ...
- HBase学习——4.HBase过滤器
1.过滤器 基础API中的查询操作在面对大量数据的时候是非常苍白的,这里Hbase提供了高级的查询方法:Filter.Filter可以根据簇.列.版本等更多的条件来对数据进行过滤,基于Hbase本身提 ...
- hbase 学习(十二)非mapreduce生成Hfile,然后导入hbase当中
最近一个群友的boss让研究hbase,让hbase的入库速度达到5w+/s,这可愁死了,4台个人电脑组成的集群,多线程入库调了好久,速度也才1w左右,都没有达到理想的那种速度,然后就想到了这种方式, ...
- HBase学习之路 (五)MapReduce操作Hbase
MapReduce从HDFS读取数据存储到HBase中 现有HDFS中有一个student.txt文件,格式如下 95002,刘晨,女,19,IS 95017,王风娟,女,18,IS 95018,王一 ...
- HBase学习笔记-高级(一)
HBase1. hbase.id记录了集群的唯一标识:hbase.version记录了文件格式的版本号2. split和.corrupt目录在日志分裂过程中使用,以便保存一些中间结果和损坏的日志在表目 ...
- HBase学习系列
转自:http://www.aboutyun.com/thread-8391-1-1.html 问题导读: 1.hbase是什么? 2.hbase原理是什么? 3.hbase使用中会遇到什么问题? 4 ...
随机推荐
- 洛谷P3242 接水果 [HNOI2015] 整体二分
正解:整体二分+树状数组 解题报告: 传送门! 题目还是大概解释下?虽然其实是看得懂的来着,,, 大概就是说给一棵树.给定一些询问,每个询问都是说在两个点之间的路径上的子路径的第k大是什么 然后看到这 ...
- 域PC脱域
SID是什么意思SID 只是安全标识符的缩写而已.SID 的全称是“安全标识符(Security Identify)”,是为域或本地计算机中创建的每个帐户分配的唯一 ID 字符串(例如,S-1-5-2 ...
- RSA 时序攻击
RSA的破解从理论上来讲是大数质数分解,可是就是有一些人另辟蹊径,根据你解密的时间长短就能破解你的RSA私钥. 举一个不恰当但是比较容易理解的例子: 密文0101 私钥0110 明文0100 问题的关 ...
- SQL 2016 AlwaysOn 无域AlwaysOn配置要点
环境准备: (1)操作系统:Windows Server 2016 Datacenter (2)SQL Server 2016 配置SQL 2016 AlwaysOn 要点 1,因为没有域所以需要在 ...
- Jmeter原理
Jmeter结构体系及运行原理 Jmeter结构体系 把Jmeter的结构体系拆分为三维空间,如图: X1~X5:是负载模拟的一个过程,使用这些组件来完成负载的模拟: X1:选择协议,模拟用户请求 ...
- Building an (awesome) API with NancyFX 2.0 + Dapper
http://blog.nandotech.com/post/2016-10-25-nancyfx-webapi-dapper/?utm_source=tuicool&utm_medium=r ...
- Elemet-技巧
<el-table-column prop="> </el-table-column> 效果: append-to-body 解决el-dialog 弹窗遮罩为题 & ...
- ABP中针对sql2008的数据库配置
- html与js和php之间实现数据交互
<div class="top3"> <input id="KeyWord" type="text" class=&quo ...
- 【Linux】-NO.8.Linux.4.Command.1.001-【Common Command】-
1.0.0 Summary Tittle:[Linux]-NO.8.Linux.4.Command.1.001-[Common Command]- Style:Linux Series:Command ...