Hbase Filter之PrefixFilter

 PrefixFilter

      PrefixFilter是将rowkey前缀为指定字符串的数据全部过滤出来并返回给用户。例如:

Scan scan = new Scan();
scan.setFilter(new PrefixFilter(Bytes.toBytes("def")));

  但是hbase的PrefixFilter比较粗暴,并没有根据filter做过多的查询优化。上述代码会scan整个区间的数据,得到一条数据就判断其是否符合前缀条件,不符合就读吓一条,直到找到前缀为def的数据。因此,我们可以指定一下startkey。

Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes("def")); scan.setFilter(new PrefixFilter(Bytes.toBytes("def"))); 

 

posted @ 2019-10-17 14:41  Evil_XJZ  阅读(2751)  评论(0编辑  收藏  举报