陈苗苗
新手
新手
  • UID498
  • 粉丝0
  • 关注0
  • 发帖数2
阅读:4797回复:0

hbase过滤器

楼主#
更多 发布于:2019-04-28 22:21


1.   行键过滤器RowFilter


比较符如下:
[table=0,white,,0,0][tr][td=1,1,253]
Operator
[/td][td=1,1,145]
Description
[/td][/tr][tr][td=1,1,253]
LESS[/td][td=1,1,145]
小于[/td][/tr][tr][td=1,1,253]
LESS_OR_EQUAL[/td][td=1,1,145]
小于等于[/td][/tr][tr][td=1,1,253]
EQUAL[/td][td=1,1,145]
等于[/td][/tr][tr][td=1,1,253]
NOT_EQUAL[/td][td=1,1,145]
不等于[/td][/tr][tr][td=1,1,253]
GREATER_OR_EQUAL[/td][td=1,1,145]
大于等于[/td][/tr][tr][td=1,1,253]
GREATER[/td][td=1,1,145]
大于[/td][/tr][tr][td=1,1,253]
NO_OP[/td][td=1,1,145]
排除所有[/td][/tr][/table]
 [table=0,white,,0,0][tr][td=1,1,235]
Comparator
[/td][td=1,1,274]
Description
[/td][/tr][tr][td=1,1,235]
BinaryComparator[/td][td=1,1,274]
使用Bytes.compareTo()比较[/td][/tr][tr][td=1,1,235]
BinaryPrefixComparator[/td][td=1,1,274]
和BinaryComparator差不多,从前面开始比较[/td][/tr][tr][td=1,1,235]
NullComparator[/td][td=1,1,274]
Does not
  compare against an actual value but whether a given one is null, or
  not null.
[/td][/tr][tr][td=1,1,235]
BitComparator[/td][td=1,1,274]
Performs a
  bitwise comparison, providing a BitwiseOp class
  with AND, OR, and XOR operators.
[/td][/tr][tr][td=1,1,235]
RegexStringComparator[/td][td=1,1,274]
正则表达式[/td][/tr][tr][td=1,1,235]
SubstringComparator[/td][td=1,1,274]
把数据当成字符串,用contains()来判断[/td][/tr][/table]
Scan scan = new Scan();
// FilterList.Operator.MUST_PASS_ALL---满足所有过滤器
FilterList list = new
FilterList(FilterList.Operator.MUST_PASS_ALL);
String rowKeyStart =
range.remove("rowKeyStart").toString();
String rowKeyEnd =
range.remove("rowKeyEnd").toString();
//因为scan会导致全表扫描,所以一般会设置开始及结束行键范围查找
if (range.get("latesttime") !=
null&& !"".equals(range.get("latesttime"))) {
scan.setReversed(true);//反向查找时,scan的开始行键和结束行键必须也反向
scan.setStartRow(rowKeyEnd.getBytes());
scan.setStopRow(rowKeyStart.getBytes());
} else {
scan.setStartRow(rowKeyStart.getBytes());
scan.setStopRow(rowKeyEnd.getBytes());
}
//匹配rowkeydDataId 结束的数据
RowFilter rowFilter = new
RowFilter(CompareFilter.CompareOp.EQUAL,
new
RegexStringComparator(".*" + dDataId + "$"));
list.addFilter(rowFilter);
Filter filter = new PageFilter(limit);//条数限制
list.addFilter(filter);
scan.setFilter(list);
//匹配rowkey以包含201407的数据
 
Filter filter = new
RowFilter(CompareFilter.CompareOp.EQUAL,
new
SubstringComparator("201407"));

 
 
 
//匹配rowkey123开头的数据
 
Filter filter = new
RowFilter(CompareFilter.CompareOp.EQUAL,
new
BinaryPrefixComparator("123".getBytes()));
游客

返回顶部