074 hbase与mapreduce集成
一:运行给定的案例
1.获取jar包里的方法

2.运行hbase自带的mapreduce程序
lib/hbase-server-0.98.6-hadoop2.jar
3.具体运行
注意命令:mapredcp。
HADOOP_CLASSPATH是当前运行时需要的环境。

4.运行一个小方法
$HADOOP_HOME/bin/yarn jar lib/hbase-server-0.98.6-hadoop2.jar rowcounter nstest1:tb1

二:自定义hbase的数据拷贝
1.需求
将nstest1:tb1的数据info:name列拷贝到nstest1:tb2
2.新建tb2表

3.书写mapreduce程序
输入:rowkey,result。
package com.beifeng.bigdat; import java.io.IOException; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper.Context;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; public class HBaseMRTest extends Configured implements Tool{
/**
* map
* @author *
*/
public static class tbMap extends TableMapper<ImmutableBytesWritable, Put>{ @Override
protected void map(ImmutableBytesWritable key, Result value,Context context) throws IOException, InterruptedException {
Put put=new Put(key.get());
for(Cell cell:value.rawCells()){
if("info".equals(Bytes.toString(CellUtil.cloneFamily(cell)))){
if("name".equals(Bytes.toString(CellUtil.cloneQualifier(cell)))){
put.add(cell);
context.write(key, put);
}
}
}
} }
/**
* reduce
* @author *
*/
public static class tbReduce extends TableReducer<ImmutableBytesWritable, Put, ImmutableBytesWritable>{ @Override
protected void reduce(ImmutableBytesWritable key, Iterable<Put> values,Context context)throws IOException, InterruptedException {
for(Put put:values){
context.write(key, put);
}
} } public int run(String[] args) throws Exception {
Configuration conf=super.getConf();
Job job =Job.getInstance(conf, "hbasemr");
job.setJarByClass(HBaseMRTest.class);
Scan scan=new Scan();
TableMapReduceUtil.initTableMapperJob(
"nstest1:tb1",
scan,
tbMap.class,
ImmutableBytesWritable.class,
Put.class,
job);
TableMapReduceUtil.initTableReducerJob(
"nstest1:tb2",
tbReduce.class,
job);
boolean issucess=job.waitForCompletion(true);
return issucess?0:1;
}
public static void main(String[] args) throws Exception{
Configuration conf=HBaseConfiguration.create();
int status=ToolRunner.run(conf, new HBaseMRTest(), args);
System.exit(status);
} }
4.打成jar包
5.运行语句
加上需要的export前提。
$HADOOP_HOME/bin/yarn jar /etc/opt/datas/HBaseMR.jar com.beifeng.bigdat.HBaseMRTest
6.效果

074 hbase与mapreduce集成的更多相关文章
- HBase概念学习(七)HBase与Mapreduce集成
这篇文章是看了HBase权威指南之后,依据上面的解说搬下来的样例,可是略微有些不一样. HBase与mapreduce的集成无非就是mapreduce作业以HBase表作为输入,或者作为输出,也或者作 ...
- HBase 与 MapReduce 集成
6. HBase 与 MapReduce 集成 6.1 官方 HBase 与 MapReduce 集成 查看 HBase 的 MapReduce 任务的执行:bin/hbase mapredcp; 环 ...
- hbase与mapreduce集成
一:运行给定的案例 1.获取jar包里的方法 2.运行hbase自带的mapreduce程序 lib/hbase-server-0.98.6-hadoop2.jar 3.具体运行 4.运行一个小方法 ...
- 【HBase】HBase与MapReduce集成——从HDFS的文件读取数据到HBase
目录 需求 步骤 一.创建maven工程,导入jar包 二.开发MapReduce程序 三.结果 需求 将HDFS路径 /hbase/input/user.txt 文件的内容读取并写入到HBase 表 ...
- hbase运行mapreduce设置及基本数据加载方法
hbase与mapreduce集成后,运行mapreduce程序,同时需要mapreduce jar和hbase jar文件的支持,这时我们需要通过特殊设置使任务可以同时读取到hadoop jar和h ...
- 【HBase】HBase与MapReduce的集成案例
目录 需求 步骤 一.创建maven工程,导入jar包 二.开发MapReduce程序 三.运行结果 HBase与MapReducer集成官方帮助文档:http://archive.cloudera. ...
- 大数据技术之_11_HBase学习_02_HBase API 操作 + HBase 与 Hive 集成 + HBase 优化
第6章 HBase API 操作6.1 环境准备6.2 HBase API6.2.1 判断表是否存在6.2.2 抽取获取 Configuration.Connection.Admin 对象的方法以及关 ...
- Hbase与hive集成与对比
HBase与Hive的对比 1.Hive (1) 数据仓库 Hive的本质其实就相当于将HDFS中已经存储的文件在Mysql中做了一个双射关系,以方便使用HQL去管理查询. (2) 用于数据分析.清洗 ...
- 《OD大数据实战》HBase整合MapReduce和Hive
一.HBase整合MapReduce环境搭建 1. 搭建步骤1)在etc/hadoop目录中创建hbase-site.xml的软连接.在真正的集群环境中的时候,hadoop运行mapreduce会通过 ...
随机推荐
- Mac改键软件Karabiner使用教程
Mac改键软件Karabiner使用教程 目前Mac上比较好用的改键软件是Karabiner,不过对于最新的Sierra系统,Karabiner失效了.这里介绍的实际上是Karabiner-Eleme ...
- .net 重新注册
今天同事问 一个IIS 的监控站点 .net 出现问题:对于windows 一般都停留在重启生效思想:然并没有生效: 于是建议重新注册.NET : 一般出现原因: 在默认安装路径 重启注册: 默认的安 ...
- Error while executing topic command : Replication factor: 2 larger than available brokers: 0.
[root@hdp1 /mnt/software/maxwell-1.19.4]#kafka-topics.sh --zookeeper hdp1,hdp2,hdp3:2181 --create -- ...
- spring源码学习1
1.下载源码: https://github.com/spring-projects/spring-framework中找到链接: git clone https://github.com/sprin ...
- pytorch官网上两个例程
caffe用起来太笨重了,最近转到pytorch,用起来实在不要太方便,上手也非常快,这里贴一下pytorch官网上的两个小例程,掌握一下它的用法: 例程一:利用nn 这个module构建网络,实现 ...
- [转]SPI通信原理简介
[转自]http://www.cnblogs.com/deng-tao/p/6004280.html 1.前言 SPI是串行外设接口(Serial Peripheral Interface)的缩写.是 ...
- WiFi基本知识【转】
转自:http://blog.csdn.net/myarrow/article/details/7930131 1. IE802.11简介 标准号 IEEE 802.11b IEEE 802.11a ...
- discuz安装:mysqli_connect()不支持advice_mysqli_connect
原文:http://blog.csdn.net/changzhi1990/article/details/40983247 php -m 输出: PHP Warning: PHP Startup: U ...
- java 对象锁学习
机制 锁机制是用来解决多线程共享资源时产生的冲突问题的.java 为每一个对象关联一个对象锁,通常把锁分为对象锁和类锁,他们的本质都是对象锁,只不过对象锁关联的是类的 Object 对象 (java. ...
- react之自定义react-redux的provider、connect
Provider // Provider把store放到context里,所有的子元素可以直接取到store import React from 'react' import PropTypes fr ...