Hbase的api中可以通过filter来实现like查询,详情如下:
对行key进行like查询:
-
private void test() throws Exception {
-
Configuration conf = getCfg();
-
Scan scan = new Scan();
-
RegexStringComparator comp = new RegexStringComparator("(##test)");
-
RowFilter filter = new RowFilter(CompareOp.EQUAL, comp);
-
scan.setFilter(filter);
-
scan.setCaching(200);
-
scan.setCacheBlocks(false);
-
HTable hTable = new HTable(conf, "Test");
-
ResultScanner scanner = hTable.getScanner(scan);
-
byte[] bytes = Bytes.toBytes("T");
-
for (Result result : scanner) {
-
String all = Bytes.toString(result.getValue(bytes, bytes));
-
System.out.println(all);
-
}
-
}
主要借助于RegexStringComparator
对列值进行like查询:
-
private void test() throws Exception {
-
Configuration conf = getCfg();
-
Scan scan = new Scan();
-
RegexStringComparator comp = new RegexStringComparator("(##test)");
-
byte[] bytes = Bytes.toBytes("T");
-
Filter filter = new SingleColumnValueFilter(bytes, bytes, CompareOp.EQUAL, comp);
-
scan.setFilter(filter);
-
scan.setCaching(200);
-
scan.setCacheBlocks(false);
-
HTable hTable = new HTable(conf, "Test");
-
ResultScanner scanner = hTable.getScanner(scan);
-
for (Result result : scanner) {
-
String all = Bytes.toString(result.getValue(bytes , bytes ));
-
System.out.println(all);
-
}
-
}
仍然是借助于RegexStringComparator
转自:http://smallnetvisitor.iteye.com/blog/1725765
阅读(3712) | 评论(1) | 转发(0) |