WalkOn主要作者之一

Hbase-前缀匹配查询

在使用sacn命令时,有时候要用到模糊查询,在网上很少关于这方面的资料,大多数都是通过java或其他语言实现,对于java不熟悉的人,通过shell命令来操作hbase相对来说较为简单。如下:

按 rowkey 模糊查询(最左前缀匹配)总行数:下面的例子会统计 r1* 的总行数:

scan 'wyk_temp',{FILTER => org.apache.hadoop.hbase.filter.PrefixFilter.new(org.apache.hadoop.hbase.util.Bytes.toBytes('r1'))}

过滤器filter有两种方法指出:
1. Using a filterString – more information on this is available in the Filter Language document attached to the HBASE-4176 JIRA
2. Using the entire package name of the filter.

-- 与pro相同的查询语句
echo "scan 'batchtb',{STARTROW=>'APP1002_DOC_LS0200010170104324', FILTER=>org.apache.hadoop.hbase.filter.PrefixFilter.new(org.apache.hadoop.hbase.util.Bytes.toBytes('APP1002_DOC_LS0200010170104324'))}" | hbase shell

echo "scan 'batchtb',{STARTROW=>'APP1009_DOC_0000000000YH000018201705170003', FILTER=>org.apache.hadoop.hbase.filter.PrefixFilter.new(org.apache.hadoop.hbase.util.Bytes.toBytes('APP1009_DOC_0000000000YH000018201705170003'))}" | ./hbase shell


评论
© 雷波光年 | Powered by LOFTER
回到顶部 ∧