Hbase表数据的导入和导出

Hbase没有提供类似于hive根据已有表的建表建表语句,如在hive中创建一个和已有表表结构完全一样的表可执行SQL:create table tbl_test1 like tbl_test,在hbase只能采用笨办法,将其表结构拷贝出来建表。如:

稍作整理:

create 'solrHbase2', {NAME => 'f1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'SNAPPY', MIN_VERSIONS => '0',KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}

需要将原表结构中的TTL => 'FOREVER'去掉才能建。

1. 导出数据

使用hbase org.apache.hadoop.hbase.mapreduce.Driver export tablename hdfspath

或hbase org.apache.hadoop.hbase.mapreduce.Export tablename hdfspath

eg:hbase org.apache.hadoop.hbase.mapreduce.Driver export solrHbase /home/hdfs/export

此命令可加参数:

解释如下:

Usage: Export [-D <property=value>]* <tablename> <outputdir> [<versions> [<starttime> [<endtime>]] [^[regex pattern] or [Prefix] to filter]]

 

  Note: -D properties will be applied to the conf used.

  For example:

   -D mapred.output.compress=true 输出压缩

   -D mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec 压缩方式

   -D mapred.output.compression.type=BLOCK 按块压缩

  Additionally, the following SCAN properties can be specified

  to control/limit what is exported..

   -D hbase.mapreduce.scan.column.family=<familyName> 列簇

   -D hbase.mapreduce.include.deleted.rows=true 

   -D hbase.mapreduce.scan.row.start=<ROWSTART> 开始rowkey

   -D hbase.mapreduce.scan.row.stop=<ROWSTOP>  终止rowkey

For performance consider the following properties:

   -Dhbase.client.scanner.caching=100 客户端缓存条数

   -Dmapred.map.tasks.speculative.execution=false

   -Dmapred.reduce.tasks.speculative.execution=false

For tables with very wide rows consider setting the batch size as below:

   -Dhbase.export.scanner.batch=10 批次大小

输入命令后会生成mapreduce作业,不想全部将表数据导出,可采用参数-D hbase.mapreduce.scan.row.start=<ROWSTART>和-D hbase.mapreduce.scan.row.stop=<ROWSTOP>指定rowkey范围导出数据。如导出指定rowkey范围的数据:

 hbase org.apache.hadoop.hbase.mapreduce.Export -D hbase.mapreduce.scan.row.start=00 -D hbase.mapreduce.scan.row.stop=0d solrHbase /home/hdfs/export

这里的开始rowkey 00和结束rowkey 0d是rowkey的开头部分,该表是做过预分区的,在hbase的控制台上看:

1. 导入数据

hbase org.apache.hadoop.hbase.mapreduce.Driver import tablename hdfspath

或hbase org.apache.hadoop.hbase.mapreduce.Import tablename hdfspath

Import也有一些使用说明:

将刚刚导出的数据导入新表中:

hbase org.apache.hadoop.hbase.mapreduce.Import solrHbase2 /home/hdfs/export

输入命令生成mapreduce作业,完成后可查看新表数据是否导入成功。

 

  • 2
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值