方式一:
hbase(main):007:0> scan 'test',{FILTER=>"FamilyFilter(=,'binaryprefix:f1')"} ROW COLUMN+CELL row-1 column=f1:c1, timestamp=1588834369334, value=v1 row-2 column=f1:c2, timestamp=1588834369334, value=v2 2 row(s) in 0.0600 seconds方式二:
import org.apache.hadoop.hbase.filter.CompareFilter import org.apache.hadoop.hbase.filter.BinaryPrefixComparator import org.apache.hadoop.hbase.filter.FamilyFilter hbase(main):011:0> scan 'test',{FILTER => FamilyFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'), BinaryPrefixComparator.new(Bytes.toBytes('f1')))} ROW COLUMN+CELL row-1 column=f1:c1, timestamp=1588834369334, value=v1 row-2 column=f1:c2, timestamp=1588834369334, value=v2 2 row(s) in 0.0290 seconds其它同上。
3. SubstringComparator 构造过滤器方式一:
hbase(main):012:0> scan 'test',{FILTER=>"FamilyFilter(=,'substring:f1')"} ROW COLUMN+CELL row-1 column=f1:c1, timestamp=1588834369334, value=v1 row-2 column=f1:c2, timestamp=1588834369334, value=v2 2 row(s) in 0.0400 seconds方式二:
import org.apache.hadoop.hbase.filter.CompareFilter import org.apache.hadoop.hbase.filter.SubstringComparator import org.apache.hadoop.hbase.filter.FamilyFilter hbase(main):016:0> scan 'test',{FILTER => FamilyFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'), SubstringComparator.new('f1'))} ROW COLUMN+CELL row-1 column=f1:c1, timestamp=1588834369334, value=v1 row-2 column=f1:c2, timestamp=1588834369334, value=v2 2 row(s) in 0.0330 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.FamilyFilter hbase(main):018:0> scan 'test',{FILTER => FamilyFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'), RegexStringComparator.new('f'))} ROW COLUMN+CELL row-1 column=f1:c1, timestamp=1588834369334, value=v1 row-2 column=f1:c2, timestamp=1588834369334, value=v2 row-3 column=f2:c3, timestamp=1588834369334, value=v3 row-4 column=f2:c4, timestamp=1588834369334, value=v4 4 row(s) in 0.0600 seconds该比较器直接传入字符串进行比较,且只支持EQUAL和NOT_EQUAL两种比较符。若想使用第一种方式可以传入regexstring试一下,我的版本有点低暂时不支持,不再演示了。
注意这里的正则匹配指包含关系,对应底层find()方法。
FamilyFilter 不支持使用LongComparator比较器,且BitComparator、NullComparator 比较器用之甚少,也不再介绍。
查看文章全部源代码请访以下GitHub地址:
https://github.com/zhoupengbo/demos-bigdata/blob/master/hbase/hbase-filters-demos/src/main/java/com/zpb/demos/FamilyFilterDemo.java