一:运行给定的案例

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集成的更多相关文章

  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. hbase与mapreduce集成

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

  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. luogu 1030 求先序遍历

    此题给出中序遍历和后序遍历后的序列,乍一看确乎想不出法子解决,毕竟是逆向思维: 但是后序遍历的特殊性质 son1,son2,x 使得后序的末尾便是根节点,再由中序天然的递归性质便可递归输出,用下fin ...

  2. 第16月底18天 phpstudy设置

    1.phpstudy设置-端口常规设置 E:\phpStudy\Apache\bin>httpd.exeAH00526: Syntax error on line 14 of E:/phpStu ...

  3. 第15月第22天 libz.dylib

    1. 3.在弹出的对话框中输入"cmd"+"shift"+"g" 4 4.输入/usr/lib https://jingyan.baidu. ...

  4. printf 函数的实现原理

    /* * ===================================================================================== * * Filen ...

  5. python的__mro__与__slot__

    class A(object): def __init__(self): print ' -> Enter A' print ' <- Leave A' class B(A): def _ ...

  6. Python(十) Python 中的 *args 和 **kwargs

    转载:团子的小窝 http://kodango.com/variable-arguments-in-python

  7. Maven入门-依赖管理(Jar包管理)(二)

    1       依赖管理(Jar包管理) 1.添加依赖  

  8. 【逆向知识】VS程序反汇编找main函数

    工具:OllyICE 调试快捷键说明: F2键:设置断点,只要在光标定位的位置 F4键:程序运行到光标处 F7键:单步步入.功能同单步步过(F8)类似,区别是遇到 CALL 等子程序时会进入其中,进入 ...

  9. python3之协程

    1.协程的概念 协程,又称微线程,纤程.英文名Coroutine. 线程是系统级别的它们由操作系统调度,而协程则是程序级别的由程序根据需要自己调度.在一个线程中会有很多函数,我们把这些函数称为子程序, ...

  10. maven配置文件setting.xml

    1.Maven本地仓库<localRepository>D:\DevTools\maven_Analytics\mavenrepo</localRepository> 2.网络 ...