hbase bulkloader实例入门

一、使用mr生成对应hbase table的hfile

maper中写入库逻辑,reduce是用hbase自带的,outputformat用的是hfileoutputformat

 

 

                        Configuration conf = new Configuration();
                        Job jobAfter = new Job(conf2);
                        jobAfter.setJarByClass(Test.class);
                        jobAfter.setMapperClass(LogicMapper.class);//在mapper中写业务逻辑
                        jobAfter.setMapOutputKeyClass(ImmutableBytesWritable.class);//只能是ImmutableBytesWritable类
                        jobAfter.setMapOutputValueClass(Put.class);//只能是put或keyvalue类型
                        FileOutputFormat.setOutputPath(jobAfter, new Path("/user/hadoop/bulkload/data"));
                        jobAfter.setOutputFormatClass(HFileOutputFormat.class);
                        HTable table=new HTable(conf,conf.get("tableName"));
                        HFileOutputFormat.configureIncrementalLoad(jobAfter, table);//根据map输出key和value设置reduce class;根据htable的region数,设置reduce数
                        jobAfter.waitForCompletion(true);

 

 

 

 

二、

将hfile导入到hbase中 

hadoop jar hbase-VERSION.jar completebulkload hdfs://localhost:8020/user/hadoop/bulkload/data testtable

 

bulkload实例二

当hbase集群和hadoop(跑MR的)集群不在一起时,就需要知道zk ip和port了

第一步

生成hfile的时候,需要hbase-site位置,里边有zk的ip和port

 

第二步

 

 

hadoop jar /home/q/hadoop/hbase-0.98.0-hadoop2/lib/hbase-server-0.98.0-hadoop2.jar  completebulkload  -Dhbase.zookeeper.quorum=192.168.xx.xx -Dhbase.zookeeper.property.clientPort=2181 hdfs://192.168.xxx.xxx:8020/user/hadoop/wfdata/testoutput xxx_table
 

 

 

192.168.xx.xx这是zk的ip 2181是zk的port

 

192.168.xxx.xxx这是hdfs上hfile的位置

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值