private void likeQuery(String tabName, String column)
throws Exception {
HTablePool pool = new HTablePool(conf, 1024);
HTableInterface table = pool.getTable(tabName);
Filter fileter = new SingleColumnValueFilter(Bytes.toBytes("gpsinfo"),
Bytes.toBytes(column), CompareOp.EQUAL,
new RegexStringComparator("[2-4]{4}"));
try {
Scan scan = new Scan();
scan.setFilter(fileter);
scan.setCaching(200);
scan.setCacheBlocks(false);
ResultScanner rs = table.getScanner(scan);
int size = 0;
for (Result result : rs) {
size++;
System.out.println("Rowkey:" + Bytes.toString(result.getRow()));
for (KeyValue keyValue : result.list()) {
System.out.println("Family:"
+ Bytes.toString(keyValue.getFamily()) + ",Column:"
+ Bytes.toString(keyValue.getQualifier())
+ ",Value:" + Bytes.toString(keyValue.getValue()));
}
}
System.out.println("=============================Size:" + size);
} catch (Exception e) {
e.printStackTrace();
} finally {
pool.close();
}
}
Like规则:
要求以ABC开头:new RegexStringComparator("^ABC")
要求以ABC结尾:new RegexStringComparator("ABC$")
要求包含ABC:new RegexStringComparator("ABC")
要求包含4位2或3或4的数值:new RegexStringComparator("[2-4]{4}")
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26798543/viewspace-765970/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26798543/viewspace-765970/