Hbase API高级特性-FilterList

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

public void filterList() throws IOException{
List filters = new ArrayList();
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();
}

你可能感兴趣的:(Hbase,API应用)