`
小网客
  • 浏览: 1219343 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Hbase实现like查询

    博客分类:
  • Java
 
阅读更多

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

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics