设为首页 加入收藏

TOP

hbase根据filter export import
2018-12-11 17:23:05 】 浏览:68
Tags:hbase 根据 filter export import

hbase的删除功能比较弱,只能单行删除,而且必须指定rowkey。


遇到问题:

今天遇到一个需求,用户导入了大量错误的数据,数据的rowkey开头都是110102,需要删除这些垃圾记录,用hbase shell删除实在不科学。


解决方案:

用hbase的mapreduce工具进行export和import,在export过程中filter掉不需要的数据。

首先说明下表的schema:

{NAME => 'freeway.service', FAMILIES => [{NAME => 'service_span_colfam', BLOOMFILTER => 'ROW', VERSIONS => '1', MIN_VERSIONS => '0', TTL => '604800', IN_MEMORY => 'true'}]}

我们使用hbase的export工具在export时filter掉不需要的数据,这边export支持正则表达式。我们看下export的usage:

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>
tablename和outputdir是必须的,后面是版本号,starttime,endtime,filter的正则表达式。

我们这里版本就一个,starttime设为0,endtime设为很大的数,保证把所有数据都拿到。后面正则表达式要用单引号包住以防Linux的bach解析里面的问号

hbase org.apache.hadoop.hbase.mapreduce.Driver export freeway.service hdfs://ns/usr/op1/freeway.service 1 0 999999999999999 '^^(!110102)'
现在这张表的数据就存在hdfs上的一个sequencefile里了。

现在删除原表,再创建一次。

然后import filter后的数据到新的表中:

hbase org.apache.hadoop.hbase.mapreduce.Driver import freeway.service hdfs://ns/usr/op1/freeway.service/part-m-00000

scan看下,woo,好了
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Hbase压缩文件 下一篇HBase的java操作,最新API。(查..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目