坚持到底

hadoop 大数据

Hbase API高级特性-FilterList

需要使用多个过滤器共同限制返回到客户端的结果。FilterList()

public void filterList() throws IOException{
List<Filter> filters = new ArrayList<Filter>();
Filter filter1 = new RowFilter(CompareFilter.CompareOp.GREATER_OR_EQUAL,
new BinaryComparator(Bytes.toBytes("3105")));
filters.add(filter1);

Filter filter2 = new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL,
new BinaryComparator(Bytes.toBytes("3107")));
filters.add(filter2);

Filter filter3  = new QualifierFilter(CompareFilter.CompareOp.EQUAL,
new SubstringComparator("th"));
filters.add(filter3);

FilterList filterList1 = new FilterList(filters);

Scan scan = new Scan();
scan.setFilter(filterList1);
ResultScanner scanner1 = table.getScanner(scan);
for(Result res : scanner1){
for(KeyValue kv: res.raw())
System.out.println("KV1: "+kv+",value: "+Bytes.toString(kv.getValue()));
}
scanner1.close();

//第二个扫描器中设置了MUST_PASS_ONE,表示只要数据通过了一个过滤器的过滤就返回
FilterList filterList2 = new FilterList(FilterList.Operator.MUST_PASS_ONE,filters);
scan.setFilter(filterList2);
ResultScanner scanner2 = table.getScanner(scan);
for(Result res : scanner2){
for(KeyValue kv: res.raw())
System.out.println("KV2: "+kv+",value: "+Bytes.toString(kv.getValue()));
}
scanner2.close();
}

阅读更多
文章标签: API hbase filter
个人分类: Hbase API应用
上一篇Hbase API高级特性-附加过滤器
下一篇Hbase API高级特性-计数器
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭