一:运行给定的案例

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.效果

  

  

  

hbase与mapreduce集成的更多相关文章

  1. HBase概念学习(七)HBase与Mapreduce集成

    这篇文章是看了HBase权威指南之后,依据上面的解说搬下来的样例,可是略微有些不一样. HBase与mapreduce的集成无非就是mapreduce作业以HBase表作为输入,或者作为输出,也或者作 ...

  2. HBase 与 MapReduce 集成

    6. HBase 与 MapReduce 集成 6.1 官方 HBase 与 MapReduce 集成 查看 HBase 的 MapReduce 任务的执行:bin/hbase mapredcp; 环 ...

  3. 074 hbase与mapreduce集成

    一:运行给定的案例 1.获取jar包里的方法 2.运行hbase自带的mapreduce程序 lib/hbase-server-0.98.6-hadoop2.jar 3.具体运行 注意命令:mapre ...

  4. 【HBase】HBase与MapReduce集成——从HDFS的文件读取数据到HBase

    目录 需求 步骤 一.创建maven工程,导入jar包 二.开发MapReduce程序 三.结果 需求 将HDFS路径 /hbase/input/user.txt 文件的内容读取并写入到HBase 表 ...

  5. hbase运行mapreduce设置及基本数据加载方法

    hbase与mapreduce集成后,运行mapreduce程序,同时需要mapreduce jar和hbase jar文件的支持,这时我们需要通过特殊设置使任务可以同时读取到hadoop jar和h ...

  6. 【HBase】HBase与MapReduce的集成案例

    目录 需求 步骤 一.创建maven工程,导入jar包 二.开发MapReduce程序 三.运行结果 HBase与MapReducer集成官方帮助文档:http://archive.cloudera. ...

  7. 大数据技术之_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 对象的方法以及关 ...

  8. Hbase与hive集成与对比

    HBase与Hive的对比 1.Hive (1) 数据仓库 Hive的本质其实就相当于将HDFS中已经存储的文件在Mysql中做了一个双射关系,以方便使用HQL去管理查询. (2) 用于数据分析.清洗 ...

  9. 《OD大数据实战》HBase整合MapReduce和Hive

    一.HBase整合MapReduce环境搭建 1. 搭建步骤1)在etc/hadoop目录中创建hbase-site.xml的软连接.在真正的集群环境中的时候,hadoop运行mapreduce会通过 ...

随机推荐

  1. C#图片处理示例(裁剪,缩放,清晰度,水印)

    C#图片处理示例(裁剪,缩放,清晰度,水印) 吴剑 2011-02-20 原创文章,转载必需注明出处:http://www.cnblogs.com/wu-jian/ 前言 需求源自项目中的一些应用,比 ...

  2. Beat the Spread![HDU1194]

    Beat the Spread! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. extjs 2.0获取选中的radio的值

    var temp=winFormPanel.getForm().findField('selectedType').getGroupValue();

  4. Remove Duplicates from Sorted List II leetcode java

    题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct ...

  5. 【wikioi】1217 借教室

    题目链接http://www.wikioi.com/problem/1217/ 算法:二分答案(线段树可过wikioi数据) 二分:http://www.wikioi.com/solution/lis ...

  6. MyEclipse设置注释格式(转载)

    Window --> Java --> Code Style --> Code Templates --> Comments --> types --> Edit ...

  7. insertAdjacentHTML和insertAdjacentText方法

    IE的DHTML对象提供了四个可读写的属性来动态操作页面元素的内容:innerText, outerText, innerHTML, outerHTML. 需注意两点: 1. 其中innerText, ...

  8. iOS开发中常见的问题

      1.重复调用2次loadView和viewDidLoad 最好不要在UIViewController的loadView方法中改变状态栏的可视性(比如状态栏由显示变为隐藏.或者由隐藏变为显示),因为 ...

  9. ITK 3.20.1 VS2010 Configuration 配置

    Download ITK 3.20.1 Download VS2010 Download CMake 3.2.0 I assume you've already installed VS2010 an ...

  10. OpenCV count the number of connected camera 检测连接的摄像头的数量

    有时候在项目中我们需要检测当前连接在机子上的摄像头的数量,可以通过下面的代码实现,其中连接摄像头的最大数量maxCamNum可以任意修改: /** * Count current camera num ...