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")));