HBase中常用过滤器有哪些

70次阅读
没有评论

丸趣 TV 小编给大家分享一下 HBase 中常用过滤器有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

1. 比较过滤器
(1) 比较过滤器的操作符

LESS  
LESS_OR_EQUAL =
EQUAL =
NOT_EQUAL
GREATER_OR_EQUAL =
GREATER
NO_OP 排除所有

 
(2)  常用比较过滤器的比较器

BinaryComparator   按字节索引顺序比较指定字节数组,采用 Bytes.compareTo(byte[])
BinaryPrefixComparator 跟前面相同,只是比较左端的数据是否相同
NullComparator 判断给定的是否为空
BitComparator 按位比较
RegexStringComparator 提供一个正则的比较器,仅支持 EQUAL 和非 EQUAL
SubstringComparator 判断提供的子串是否出现在 value 中

 
(3)  比较过滤器的实际应用
3-1) 行键过滤器 RowFilter

Filter filter = new RowFilter(CompareOp.LESS_OR_EQUAL,new BinaryComparator(Bytes.toBytes( row-22)));
scan.setFilter(filter);
 
Filter filter1 = new RowFilter(CompareOp.EQUAL, new SubstringComparator( -5));
scan.setFilter(filter1);

 
3-2)  列族过滤器 FamilyFilter

Filter filter1 = new FamilyFilter(CompareFilter.CompareOp.LESS, new BinaryComparator(Bytes.toBytes( colfam3)));
scan.setFilter(filter1); 

 
3-3)  列过滤器 QualifierFilter

filter = new QualifierFilter(CompareFilter.CompareOp.LESS_OR_EQUAL, new BinaryComparator(Bytes.toBytes( col-2)));
scan.setFilter(filter1);

   
3-4)  值过滤器 ValueFilter

Filter filter = new ValueFilter(CompareFilter.CompareOp.EQUAL, new SubstringComparator( .4) ); 
scan.setFilter(filter1);

   
2. 专用过滤器
(1) 前缀过滤器 PrefixFilter – 针对行键

Filter fileter = new PrefixFilter(Bytes.toBytes( hello));
scan.setFilter(fileter);

 
(2)  列前缀过滤器

Filter fileter = new ColumnPrefixFilter(Bytes.toBytes( hello));
scan.setFilter(filter);

 
3. 正则表达式过滤(RegexStringComparator)

Scan scan = new Scan();
RegexStringComparator comp = new RegexStringComparator(you. // 以 you 开头的字符串
SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes( family), Bytes.toBytes(qualifier), CompareOp.EQUAL, comp);
scan.setFilter(filter);

 
4. SubStringComparator
用于监测一个子串是否存在于值中,并且不区分大小写。

Scan scan = new Scan();
SubstringComparator comp = new SubstringComparator(1129 // 查找包含 1129 的字符串
SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes( family), Bytes.toBytes(qualifier), CompareOp.EQUAL, comp);
scan.setFilter(filter);

 
5. 布隆过滤器 BloomFilter
简介:hbase 的 storefile 有很多,随机查的时候可能需要遍历很多 storefile,如果在建表的时候指定了 bloomfilter,则在 get 查询(scan 不管用)的时候就可以过滤掉很多不符合规则的 storefile,提高查询效率。

以上是“HBase 中常用过滤器有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!