HBase Filter 过滤器之QualifierFilter详解 (2)

方式一:

hbase(main):003:0> scan 'test',{FILTER=>"QualifierFilter(=,'binary:age')"} ROW COLUMN+CELL row-1 column=f:age, timestamp=1589252853542, value=20 row-2 column=f:age, timestamp=1589252853542, value=10 row-4 column=f:age, timestamp=1589252853542, value=Zhao 3 row(s) in 0.0680 seconds

支持的比较运算符:= != > >= < <=,不再一一举例。

方式二:

import org.apache.hadoop.hbase.filter.CompareFilter import org.apache.hadoop.hbase.filter.BinaryComparator import org.apache.hadoop.hbase.filter.QualifierFilter hbase(main):010:0> scan 'test',{FILTER => QualifierFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'), BinaryComparator.new(Bytes.toBytes('age')))} ROW COLUMN+CELL row-1 column=f:age, timestamp=1589252853542, value=20 row-2 column=f:age, timestamp=1589252853542, value=10 row-4 column=f:age, timestamp=1589252853542, value=Zhao 3 row(s) in 0.0400 seconds

支持的比较运算符:LESS、LESS_OR_EQUAL、EQUAL、NOT_EQUAL、GREATER、GREATER_OR_EQUAL,不再一一举例。

推荐使用方式一,更简洁方便。

2. BinaryPrefixComparator 构造过滤器

方式一:

hbase(main):011:0> scan 'test',{FILTER=>"QualifierFilter(=,'binaryprefix:nam')"} ROW COLUMN+CELL row-1 column=f:name, timestamp=1589252853542, value=Wang row-2 column=f:name, timestamp=1589252853542, value=Zhou row-3 column=f:name, timestamp=1589252853542, value=Li row-4 column=f:namana, timestamp=1589252853542, value=xyz 4 row(s) in 0.0410 seconds

方式二:

import org.apache.hadoop.hbase.filter.CompareFilter import org.apache.hadoop.hbase.filter.BinaryPrefixComparator import org.apache.hadoop.hbase.filter.QualifierFilter hbase(main):014:0> scan 'test',{FILTER => QualifierFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'), BinaryPrefixComparator.new(Bytes.toBytes('nam')))} ROW COLUMN+CELL row-1 column=f:name, timestamp=1589252853542, value=Wang row-2 column=f:name, timestamp=1589252853542, value=Zhou row-3 column=f:name, timestamp=1589252853542, value=Li row-4 column=f:namana, timestamp=1589252853542, value=xyz 4 row(s) in 0.0200 seconds

其它同上。

3. SubstringComparator 构造过滤器

方式一:

hbase(main):015:0> scan 'test',{FILTER=>"QualifierFilter(=,'substring:am')"} ROW COLUMN+CELL row-1 column=f:name, timestamp=1589252853542, value=Wang row-2 column=f:name, timestamp=1589252853542, value=Zhou row-3 column=f:name, timestamp=1589252853542, value=Li row-4 column=f:namana, timestamp=1589252853542, value=xyz 4 row(s) in 0.0230 seconds

方式二:

import org.apache.hadoop.hbase.filter.CompareFilter import org.apache.hadoop.hbase.filter.SubstringComparator import org.apache.hadoop.hbase.filter.QualifierFilter hbase(main):017:0> scan 'test',{FILTER => QualifierFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'), SubstringComparator.new('am'))} ROW COLUMN+CELL row-1 column=f:name, timestamp=1589252853542, value=Wang row-2 column=f:name, timestamp=1589252853542, value=Zhou row-3 column=f:name, timestamp=1589252853542, value=Li row-4 column=f:namana, timestamp=1589252853542, value=xyz 4 row(s) in 0.0220 seconds

区别于上的是这里直接传入字符串进行比较,且只支持EQUAL和NOT_EQUAL两种比较符。

4. RegexStringComparator 构造过滤器 import org.apache.hadoop.hbase.filter.CompareFilter import org.apache.hadoop.hbase.filter.RegexStringComparator import org.apache.hadoop.hbase.filter.QualifierFilter hbase(main):019:0> scan 'test',{FILTER => QualifierFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'), RegexStringComparator.new('n[a-z]m'))} ROW COLUMN+CELL row-1 column=f:name, timestamp=1589252853542, value=Wang row-2 column=f:name, timestamp=1589252853542, value=Zhou row-3 column=f:name, timestamp=1589252853542, value=Li row-4 column=f:namana, timestamp=1589252853542, value=xyz 4 row(s) in 0.0250 seconds

该比较器直接传入字符串进行比较,且只支持EQUAL和NOT_EQUAL两种比较符。若想使用第一种方式可以传入regexstring试一下,我的版本有点低暂时不支持,不再演示了。

注意这里的正则匹配指包含关系,对应底层find()方法。

QualifierFilter 不支持使用LongComparator比较器,且BitComparator、NullComparator 比较器用之甚少,也不再介绍。

查看文章全部源代码请访以下GitHub地址:

https://github.com/zhoupengbo/demos-bigdata/blob/master/hbase/hbase-filters-demos/src/main/java/com/zpb/demos/QualifierFilterDemo.java

扫描二维码关注博主公众号

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsxfjp.html