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,提高查询效率。
参考:http://blog.csdn.net/opensure/article/details/46453681
6. 更多过滤器实例
参考:http://blog.csdn.net/u012185296/article/details/47338549
更多精彩内容,请访问:圈里圈外
来源:oschina
链接:https://my.oschina.net/u/2540431/blog/715724