hbase權威指南閱讀隨手筆記二之過濾器
base過濾器的比較運算子:
2.1 SingleColumnValueFilter
LESS <
LESS_OR_EQUAL <=
EQUAL =
NOT_EQUAL <>
GREATER_OR_EQUAL >=
GREATER >
NO_OP no operation
比較器:
Hbase的過濾器分類
BinaryComparator 按位元組索引順序比較指定位元組陣列,採用Bytes.compareTo(byte[])
BinaryPrefixComparator 跟前面相同,只是比較左端的資料是否相同
NullComparator 判斷給定的是否為空
BitComparator 按位比較 a BitwiseOp class 做異或,與,並操作
RegexStringComparator 提供一個正則的比較器,僅支援 EQUAL 和非EQUALSubstringComparator 判斷提供的子串是否出現在table的value中。
比較過濾器
1、Comparision Filters
1.1 RowFilter
1.1 RowFilter
建構函式選擇比較rowkey來確定選擇合適的行資訊。
- public RowFilter(org.apache.hadoop.hbase.filter.CompareFilter.CompareOp rowCompareOp, org.apache.hadoop.hbase.filter.WritableByteArrayComparable rowComparator) {}
1.2 FamilyFilter
- public class RowFilterExample {
- public static void main(String[] args) throws IOException {
- Configuration conf = HBaseConfiguration.create();
- HBaseHelper helper = HBaseHelper.getHelper(conf);
- helper.dropTable("testtable");
- helper.createTable("testtable", "colfam1", "colfam2");
- System.out.println("Adding rows to table...");
- helper.fillTable("testtable", 1, 100, 100, "colfam1", "colfam2");
- HTable table = new HTable(conf, "testtable");
- // vv RowFilterExample
- Scan scan = new Scan();
- scan.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col-0"));
- Filter filter1 = new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL, // co RowFilterExample-1-Filter1 Create filter, while specifying the comparison operator and comparator. Here an exact match is needed.
- new BinaryComparator(Bytes.toBytes("row-22")));
- scan.setFilter(filter1);
- ResultScanner scanner1 = table.getScanner(scan);
- // ^^ RowFilterExample
- System.out.println("Scanning table #1...");
- // vv RowFilterExample
- for (Result res : scanner1) {
- System.out.println(res);
- }
- scanner1.close();
- Filter filter2 = new RowFilter(CompareFilter.CompareOp.EQUAL, // co RowFilterExample-2-Filter2 Another filter, this time using a regular expression to match the row keys.
- new RegexStringComparator(".*-.5"));
- scan.setFilter(filter2);
- ResultScanner scanner2 = table.getScanner(scan);
- // ^^ RowFilterExample
- System.out.println("Scanning table #2...");
- // vv RowFilterExample
- for (Result res : scanner2) {
- System.out.println(res);
- }
- scanner2.close();
- Filter filter3 = new RowFilter(CompareFilter.CompareOp.EQUAL, // co RowFilterExample-3-Filter3 The third filter uses a substring match approach.
- new SubstringComparator("-5"));
- scan.setFilter(filter3);
- ResultScanner scanner3 = table.getScanner(scan);
- // ^^ RowFilterExample
- System.out.println("Scanning table #3...");
- // vv RowFilterExample
- for (Result res : scanner3) {
- System.out.println(res);
- }
- scanner3.close();
- // ^^ RowFilterExample
- }
- }
建構函式
- public FamilyFilter(CompareOp familyCompareOp, WritableByteArrayComparable familyComparator) {}
透過和列簇比較得到,返回結果為真的資料,示例:
- public class FamilyFilterExample {
- public static void main(String[] args) throws IOException {
- Configuration conf = HBaseConfiguration.create();
- HBaseHelper helper = HBaseHelper.getHelper(conf);
- helper.dropTable("testtable");
- helper.createTable("testtable", "colfam1", "colfam2", "colfam3", "colfam4");
- System.out.println("Adding rows to table...");
- helper.fillTable("testtable", 1, 10, 2, "colfam1", "colfam2", "colfam3", "colfam4");
- HTable table = new HTable(conf, "testtable");
- // vv FamilyFilterExample
- Filter filter1 = new FamilyFilter(CompareFilter.CompareOp.LESS, // co FamilyFilterExample-1-Filter Create filter, while specifying the comparison operator and comparator.
- new BinaryComparator(Bytes.toBytes("colfam3")));
- Scan scan = new Scan();
- scan.setFilter(filter1);
- ResultScanner scanner = table.getScanner(scan); // co FamilyFilterExample-2-Scan Scan over table while applying the filter.
- // ^^ FamilyFilterExample
- System.out.println("Scanning table... ");
- // vv FamilyFilterExample
- for (Result result : scanner) {
- System.out.println(result);
- }
- scanner.close();
- Get get1 = new Get(Bytes.toBytes("row-5"));
- get1.setFilter(filter1);
- Result result1 = table.get(get1); // co FamilyFilterExample-3-Get Get a row while applying the same filter.
- System.out.println("Result of get(): " + result1);
- Filter filter2 = new FamilyFilter(CompareFilter.CompareOp.EQUAL,
- new BinaryComparator(Bytes.toBytes("colfam3")));
- Get get2 = new Get(Bytes.toBytes("row-5")); // co FamilyFilterExample-4-Mismatch Create a filter on one column family while trying to retrieve another.
- get2.addFamily(Bytes.toBytes("colfam1"));
- get2.setFilter(filter2);
- Result result2 = table.get(get2); // co FamilyFilterExample-5-Get2 Get the same row while applying the new filter, this will return "NONE".
- System.out.println("Result of get(): " + result2);
- // ^^ FamilyFilterExample
- }
- }
1.3 QualifierFilter
1.4 ValueFilter建構函式透過和列名比較,返回為真的資料,示例:
- public QualifierFilter(CompareOp qualifierCompareOp, WritableByteArrayComparable qualifierComparator) { }
- // vv QualifierFilterExample
- Filter filter = new QualifierFilter(CompareFilter.CompareOp.LESS_OR_EQUAL,
- new BinaryComparator(Bytes.toBytes("col-2")));
- Scan scan = new Scan();
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- // ^^ QualifierFilterExample
- System.out.println("Scanning table... ");
- // vv QualifierFilterExample
- for (Result result : scanner) {
- System.out.println(result);
- }
- scanner.close();
- Get get = new Get(Bytes.toBytes("row-5"));
- get.setFilter(filter);
- Result result = table.get(get);
- System.out.println("Result of get(): " + result);
建構函式
"code" class="java" style="color: rgb(88, 89, 93); font-size: 14px; line-height: 25px;">public ValueFilter(CompareOp valueCompareOp, WritableByteArrayComparable valueComparator) {}- 透過和列名比較,返回為真的資料,示例:
- Filter filter = new ValueFilter(CompareFilter.CompareOp.EQUAL, // co ValueFilterExample-1-Filter Create filter, while specifying the comparison operator and comparator.
- new SubstringComparator(".4") );
- Scan scan = new Scan();
- scan.setFilter(filter); // co ValueFilterExample-2-SetFilter Set filter for the scan.
- ResultScanner scanner = table.getScanner(scan);
- // ^^ ValueFilterExample
- System.out.println("Results of scan:");
- // vv ValueFilterExample
- for (Result result : scanner) {
- for (KeyValue kv : result.raw()) {
- System.out.println("KV: " + kv + ", Value: " + // co ValueFilterExample-3-Print1 Print out value to check that filter works.
- Bytes.toString(kv.getValue()));
- }
- }
- scanner.close();
- Get get = new Get(Bytes.toBytes("row-5"));
- get.setFilter(filter); // co ValueFilterExample-4-SetFilter2 Assign same filter to Get instance.
- Result result = table.get(get);
- // ^^ ValueFilterExample
- System.out.println("Result of get: ");
- // vv ValueFilterExample
- for (KeyValue kv : result.raw()) {
- System.out.println("KV: " + kv + ", Value: " +
- Bytes.toString(kv.getValue()));
- }
1.5 DependentColumnFilter
該過濾器有兩個引數 —— 列族和列修飾。 嘗試找到該列所在的每一行,並返回該行具有相同時間戳的全部鍵值對。如果某一行不包含指定的列,則該行的任何鍵值對都不返回。
該過濾器還可以有一個可選布林引數 —— dropDependentColumn. 如果為true, 從屬的列不返回。
該過濾器還可以有兩個可選引數 —— 一個比較運算子和一個值比較器,用於列族和修飾的進一步檢查。如果從屬的列找到,其值還必須透過值檢查,然後就是時間戳必須考慮。
2、Dedicated Filters
- package filters;
- // cc DependentColumnFilterExample Example using a filter to include only specific column families
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.hbase.HBaseConfiguration;
- import org.apache.hadoop.hbase.KeyValue;
- import org.apache.hadoop.hbase.client.Get;
- import org.apache.hadoop.hbase.client.HTable;
- import org.apache.hadoop.hbase.client.Result;
- import org.apache.hadoop.hbase.client.ResultScanner;
- import org.apache.hadoop.hbase.client.Scan;
- import org.apache.hadoop.hbase.filter.BinaryPrefixComparator;
- import org.apache.hadoop.hbase.filter.CompareFilter;
- import org.apache.hadoop.hbase.filter.DependentColumnFilter;
- import org.apache.hadoop.hbase.filter.Filter;
- import org.apache.hadoop.hbase.filter.RegexStringComparator;
- import org.apache.hadoop.hbase.filter.WritableByteArrayComparable;
- import org.apache.hadoop.hbase.util.Bytes;
- import util.HBaseHelper;
- import java.io.IOException;
- public class DependentColumnFilterExample {
- private static HTable table = null;
- // vv DependentColumnFilterExample
- private static void filter(boolean drop,
- CompareFilter.CompareOp operator,
- WritableByteArrayComparable comparator)
- throws IOException {
- Filter filter;
- if (comparator != null) {
- filter = new DependentColumnFilter(Bytes.toBytes("colfam1"), // co DependentColumnFilterExample-1-CreateFilter Create the filter with various options.
- Bytes.toBytes("col-5"), drop, operator, comparator);
- } else {
- filter = new DependentColumnFilter(Bytes.toBytes("colfam1"),
- Bytes.toBytes("col-5"), drop);
- }
- Scan scan = new Scan();
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- // ^^ DependentColumnFilterExample
- System.out.println("Results of scan:");
- // vv DependentColumnFilterExample
- for (Result result : scanner) {
- for (KeyValue kv : result.raw()) {
- System.out.println("KV: " + kv + ", Value: " +
- Bytes.toString(kv.getValue()));
- }
- }
- scanner.close();
- Get get = new Get(Bytes.toBytes("row-5"));
- get.setFilter(filter);
- Result result = table.get(get);
- // ^^ DependentColumnFilterExample
- System.out.println("Result of get: ");
- // vv DependentColumnFilterExample
- for (KeyValue kv : result.raw()) {
- System.out.println("KV: " + kv + ", Value: " +
- Bytes.toString(kv.getValue()));
- }
- // ^^ DependentColumnFilterExample
- System.out.println("");
- // vv DependentColumnFilterExample
- }
- public static void main(String[] args) throws IOException {
- // ^^ DependentColumnFilterExample
- Configuration conf = HBaseConfiguration.create();
- HBaseHelper helper = HBaseHelper.getHelper(conf);
- helper.dropTable("testtable");
- helper.createTable("testtable", "colfam1", "colfam2");
- System.out.println("Adding rows to table...");
- helper.fillTable("testtable", 1, 10, 10, true, "colfam1", "colfam2");
- table = new HTable(conf, "testtable");
- // vv DependentColumnFilterExample
- filter(true, CompareFilter.CompareOp.NO_OP, null);
- filter(false, CompareFilter.CompareOp.NO_OP, null); // co DependentColumnFilterExample-2-Filter Call filter method with various options.
- filter(true, CompareFilter.CompareOp.EQUAL,
- new BinaryPrefixComparator(Bytes.toBytes("val-5")));
- filter(false, CompareFilter.CompareOp.EQUAL,
- new BinaryPrefixComparator(Bytes.toBytes("val-5")));
- filter(true, CompareFilter.CompareOp.EQUAL,
- new RegexStringComparator(".*\\.5"));
- filter(false, CompareFilter.CompareOp.EQUAL,
- new RegexStringComparator(".*\\.5"));
- }
- // ^^ DependentColumnFilterExample}
2.1 SingleColumnValueFilter
選定列簇和某一列,然後與列的value相比,正確的返回全部的row,注意如果某一行不含有該列,同樣返回,除非透過filterIfColumnMissing 設定成真。
建構函式
"code" class="java">SingleColumnValueFilter(byte[] family, byte[] qualifier, CompareOp compareOp, byte[] value)- SingleColumnValueFilter(byte[] family, byte[] qualifier, CompareOp compareOp, WritableByteArrayComparable comparator)
- 第一個建構函式相當於構建了一個BinaryComparator的例項。其他的跟CompareFilter的引數含義一樣。
該過濾器透過下面兩個引數 filterIfMissing,latestVersionOnly
如果 filterIfColumnMissing 標誌設為真,如果該行沒有指定的列,那麼該行的所有列將不發出。預設值為假。
- boolean getFilterIfMissing()
- void setFilterIfMissing(boolean filterIfMissing)
- boolean getLatestVersionOnly()
- void setLatestVersionOnly(boolean latestVersionOnly)
如果setLatestVersionOnly 標誌設為假,將檢查此前的版本。預設值為真。例項如下:
- // vv SingleColumnValueFilterExample
- SingleColumnValueFilter filter = new SingleColumnValueFilter(
- Bytes.toBytes("colfam1"),
- Bytes.toBytes("col-5"),
- CompareFilter.CompareOp.NOT_EQUAL,
- new SubstringComparator("val-5"));
- filter.setFilterIfMissing(true);
- Scan scan = new Scan();
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- // ^^ SingleColumnValueFilterExample
- System.out.println("Results of scan:");
- // vv SingleColumnValueFilterExample
- for (Result result : scanner) {
- for (KeyValue kv : result.raw()) {
- System.out.println("KV: " + kv + ", Value: " +
- Bytes.toString(kv.getValue()));
- }
- }
- scanner.close();
- Get get = new Get(Bytes.toBytes("row-6"));
- get.setFilter(filter);
- Result result = table.get(get);
- System.out.println("Result of get: ");
- for (KeyValue kv : result.raw()) {
- System.out.println("KV: " + kv + ", Value: " +
- Bytes.toString(kv.getValue()));
- }
2.2 SingleColumnValueExcludeFilter
該過濾器同上面的過濾器正好相反,如果條件相符,將不會返回該列的內容。
2.3 PrefixFilter
所有的row的例項匹配prefix的時候返回結果集合
2.4 PageFilter
- Filter filter = new PrefixFilter(Bytes.toBytes("row1"));
- Scan scan = new Scan();
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for(Result result: scanner){
- for(KeyValue kv: result.raw()) {
- System.out.println("KV:" + kv + ", Value:" + Bytes.toString(kv.getValue()));
- }
- }
- scanner.close();
- Get get = new Get(Bytes.toBytes("row-5"));
- get.setFilter(filter);
- Result result = table.get(get);
- for(KeyValue kv : result.raw()){
- System.out.println("KV:" + kv + ", Value:" + Bytes.toString(kv.getValue()));
- }
頁過濾,透過設定pagesize引數可以返回每一頁page的數量。
客戶端需要記住上一次訪問的row的key值。
因為hbase的row是字典序列排列的,因此上一次的lastrow需要新增額外的0表示新的開始。另外startKey的那一行是包含在scan裡面的。
- package hbaseTest;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.hbase.HBaseConfiguration;
- import org.apache.hadoop.hbase.client.HTable;
- import org.apache.hadoop.hbase.client.Result;
- import org.apache.hadoop.hbase.client.ResultScanner;
- import org.apache.hadoop.hbase.client.Scan;
- import org.apache.hadoop.hbase.filter.Filter;
- import org.apache.hadoop.hbase.filter.PageFilter;
- import org.apache.hadoop.hbase.util.Bytes;
- import java.io.IOException;
- /**
- * Hello world!
- */
- public class PageFilterExample {
- public static void main(String[] args) throws IOException {
- Configuration config = HBaseConfiguration.create();
- config.set("hbase.zookeeper.quorum", "QT-H-0038");
- String tableName = "testTable";
- String cfName = "colfam1";
- final byte[] POSTFIX = new byte[] { 0x00 };
- HTable table = new HTable(config, tableName);
- Filter filter = new PageFilter(15);
- byte[] lastRow = null;
- int totalRows = 0;
- while (true) {
- Scan scan = new Scan();
- scan.setFilter(filter);
- if(lastRow != null){
- //注意這裡新增了POSTFIX操作,不然死迴圈了
- byte[] startRow = Bytes.add(lastRow,POSTFIX);
- scan.setStartRow(startRow);
- }
- ResultScanner scanner = table.getScanner(scan);
- int localRows = 0;
- Result result;
- while((result = scanner.next()) != null){
- System.out.println(localRows++ + ":" + result);
- totalRows ++;
- lastRow = result.getRow();
- }
- scanner.close();
- if(localRows == 0) break;
- }
- System.out.println("total rows:" + totalRows);
- }
- }
2.5 KeyOnlyFilter
因為一些應用只想獲取data資料,而不是真實的val,可以使用這個過濾器。該過濾器透過
lenAsVal預設為假,表示不把val的長度作為val。否則 val的長度將作為val輸出。
- KeyOnlyFilter(boolean lenAsVal)
- final byte[] POSTFIX = new byte[] { 0x00 };
- HTable table = new HTable(config, tableName);
- Filter filter = new KeyOnlyFilter(false);
- byte[] lastRow = null;
- int totalRows = 0;
- Scan scan = new Scan();
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for(Result result: scanner){
- for(KeyValue kv: result.raw()){
- System.out.println(kv + ":" + Bytes.toString(kv.getValue()));
- }
- }
2.6 FirstKeyOnlyFilter
在對hbase的表進行掃描的時候,如果指定了FirstKeyOnlyFilter過濾條件則僅僅會返回相同key的第一條kv。
當對hbase中的表進行count,sum操作等集合操作的時候,使用FirstKeyOnlyFilter會帶來效能上的提升。
返回的結果是
- public class KeyOnlyFilterExample {
- public static void main(String[] args) throws IOException {
- Configuration config = HBaseConfiguration.create();
- config.set("hbase.zookeeper.quorum", "QT-H-0038");
- String tableName = "testTable";
- String cfName = "colfam1";
- final byte[] POSTFIX = new byte[] { 0x00 };
- HTable table = new HTable(config, tableName);
- Filter filter = new FirstKeyOnlyFilter();
- byte[] lastRow = null;
- int totalRows = 0;
- Scan scan = new Scan();
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for(Result result: scanner){
- for(KeyValue kv: result.raw()){
- System.out.println(kv + ":" + Bytes.toString(kv.getValue()));
- }
- }
- }
- }
- row-5/colfam1:qual1/1354673733503/Put/vlen=4:row1
- row1/colfam1:qual1/1354432930568/Put/vlen=4:val1
- row2/colfam1:qual2/1354432930568/Put/vlen=4:val3
如果註釋掉過濾器的返回的結果是:
- row-5/colfam1:qual1/1354673733503/Put/vlen=4:row1
- row1/colfam1:qual1/1354432930568/Put/vlen=4:val1
- row1/colfam1:qual2/1354435819120/Put/vlen=4:val2
- row2/colfam1:qual2/1354432930568/Put/vlen=4:val3
2.7 InclusiveStopFilter
因為hbase的scan包含start-row不包含stop-row 如果使用這個過濾器我們可以包含stop-row
- HTable table = new HTable(config, tableName);
- Filter filter = new InclusiveStopFilter(Bytes.toBytes("row1"));
- Scan scan = new Scan();
- scan.setFilter(filter);
- scan.setStartRow(Bytes.toBytes("row-5"));
- ResultScanner scanner = table.getScanner(scan);
- for(Result result: scanner){
- System.out.println(result);
- }
會看到row1包含在結果中了。
2.8 TimestampsFilter
當訪問某個Timestamp的新聞的時候,我們需要如下的程式碼:
- TimestampsFilter(List
timestamps) 接受的引數的list引數,該Filter也可以和scan.setTimeRange混合使用。例如:
- // vv TimestampFilterExample
- List
ts = new ArrayList (); - ts.add(new Long(5));
- ts.add(new Long(10)); // co TimestampFilterExample-1-AddTS Add timestamps to the list.
- ts.add(new Long(15));
- Filter filter = new TimestampsFilter(ts);
- Scan scan1 = new Scan();
- scan1.setFilter(filter); // co TimestampFilterExample-2-AddFilter Add the filter to an otherwise default Scan instance.
- ResultScanner scanner1 = table.getScanner(scan1);
- // ^^ TimestampFilterExample
- System.out.println("Results of scan #1:");
- // vv TimestampFilterExample
- for (Result result : scanner1) {
- System.out.println(result);
- }
- scanner1.close();
- Scan scan2 = new Scan();
- scan2.setFilter(filter);
- scan2.setTimeRange(8, 12); // co TimestampFilterExample-3-AddTSRange Also add a time range to verify how it affects the filter
- ResultScanner scanner2 = table.getScanner(scan2);
- // ^^ TimestampFilterExample
- System.out.println("Results of scan #2:");
- // vv TimestampFilterExample
- for (Result result : scanner2) {
- System.out.println(result);
- }
- scanner2.close();
2.9 ColumnCountGetFilter
這個在scan時,無用。
2.10 ColumnPaginationFilter(下來用到的時候在仔細研究下)
* A filter, based on the ColumnCountGetFilter, takes two arguments: limit and offset.
* This filter can be used for row-based indexing, where references to other tables are stored across many columns,
* in order to efficient lookups and paginated results for end users.
- Filter filter = new ColumnPaginationFilter(5, 15);
- Scan scan = new Scan();
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- // ^^ ColumnPaginationFilterExample
- System.out.println("Results of scan:");
- // vv ColumnPaginationFilterExample
- for (Result result : scanner) {
- System.out.println(result);
- }
- scanner.close();
2.11 ColumnPrefixFilter
跟prefxiFilter相似,只是改成了Column,例項如下:值scan到與列值與前面匹配的資料。例如qual2匹配qual21。
- // vv ColumnPaginationFilterExample
- Filter filter = new ColumnPrefixFilter(Bytes.toBytes("qual2"));
- Scan scan = new Scan();
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- // ^^ ColumnPaginationFilterExample
- System.out.println("Results of scan:");
- // vv ColumnPaginationFilterExample
- for (Result result : scanner) {
- System.out.println(result);
- }
- scanner.close();
2.12 RandomRowFilter
隨即的返回row的資料,建構函式為chance取值為0到1.0,如果<0則為空,如果>1則包含所有的行。
- RandomRowFilter(float chance)
3、Decorating Filters
裝飾性過濾器3.1 SkipFilter
這個過濾器只作用到keyValueFilter上。KeyValueFilter會返回所有滿足條件的row及對應的列。
而加上SkipFilter以後。會發現如果某一行的某一列不符合條件,則這一行全部不返回了。
- public static void main(String[] args) throws IOException {
- Configuration conf = HBaseConfiguration.create();
- HBaseHelper helper = HBaseHelper.getHelper(conf);
- helper.dropTable("testtable");
- helper.createTable("testtable", "colfam1");
- System.out.println("Adding rows to table...");
- helper.fillTable("testtable", 1, 30, 5, 2, true, true, "colfam1");
- HTable table = new HTable(conf, "testtable");
- // vv SkipFilterExample
- Filter filter1 = new ValueFilter(CompareFilter.CompareOp.NOT_EQUAL,
- new BinaryComparator(Bytes.toBytes("val-0")));
- Scan scan = new Scan();
- scan.setFilter(filter1); // co SkipFilterExample-1-AddFilter1 Only add the ValueFilter to the first scan.
- ResultScanner scanner1 = table.getScanner(scan);
- // ^^ SkipFilterExample
- System.out.println("Results of scan #1:");
- int n = 0;
- // vv SkipFilterExample
- for (Result result : scanner1) {
- for (KeyValue kv : result.raw()) {
- System.out.println("KV: " + kv + ", Value: " +
- Bytes.toString(kv.getValue()));
- // ^^ SkipFilterExample
- n++;
- // vv SkipFilterExample
- }
- }
- scanner1.close();
- Filter filter2 = new SkipFilter(filter1);
- scan.setFilter(filter2); // co SkipFilterExample-2-AddFilter2 Add the decorating skip filter for the second scan.
- ResultScanner scanner2 = table.getScanner(scan);
- // ^^ SkipFilterExample
- System.out.println("Total KeyValue count for scan #1: " + n);
- n = 0;
- System.out.println("Results of scan #2:");
- // vv SkipFilterExample
- for (Result result : scanner2) {
- for (KeyValue kv : result.raw()) {
- System.out.println("KV: " + kv + ", Value: " +
- Bytes.toString(kv.getValue()));
- // ^^ SkipFilterExample
- n++;
- // vv SkipFilterExample
- }
- }
- scanner2.close();
- // ^^ SkipFilterExample
- System.out.println("Total KeyValue count for scan #2: " + n);
- }
3.2 WhileMatchFilters
相當於while執行,知道不match就break了返回了。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29754888/viewspace-1258697/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- javascript權威指南閱讀筆記2JavaScript筆記
- 《IDA pro權威指南》閱讀筆記筆記
- 《Git權威指南》讀書筆記Git筆記
- 讀書筆記【JS 權威指南】14.1 計時器筆記JS
- 《IDA Pro權威指南》讀書筆記筆記
- HBase權威指南【中文版】
- hbase過濾器過濾器
- Vue原始碼閱讀--過濾器Vue原始碼過濾器
- 讀書筆記【JS 權威指南】14.2 瀏覽器定位和導航筆記JS瀏覽器
- HBase Filter 過濾器之 ValueFilter 詳解Filter過濾器
- 讀《Cassandra權威指南》
- 《Angular權威教程》讀書筆記Angular筆記
- [心得] JavaScript權威指南學習筆記JavaScript筆記
- MongoDB權威指南學習筆記03MongoDB筆記
- 《AngularJs權威指南》學習筆記---指令AngularJS筆記
- ASP.NET MVC筆記 之 Action 過濾器ASP.NETMVC筆記過濾器
- 《JavaScript 學習指南》閱讀筆記(一)JavaScript筆記
- 《HTTPS權威指南》-協議學習筆記HTTP協議筆記
- asp.net core MVC 過濾器之ActionFilter過濾器(二)ASP.NETMVC過濾器Filter
- 《人月神話》閱讀筆記二筆記
- 隨手查閱的正則匹配筆記筆記
- 008-讀書筆記-Vue官網 過濾器筆記Vue過濾器
- Angular權威教程閱讀總結(1)Angular
- 《架構之美》閱讀筆記架構筆記
- HTML5權威指南讀書筆記25(完結)(第37章)--使用拖放HTML筆記
- Shiro筆記--shiroFilter許可權過濾筆記Filter
- 《IDA Pro權威指南(第2版)》編輯手記
- 閱讀筆記筆記
- Hbase 布隆過濾器BloomFilter介紹過濾器OOMFilter
- HTTP 1.x 學習筆記 —— Web 效能權威指南HTTP筆記Web
- JavaScript 權威指南(第六版)學習筆記JavaScript筆記
- 《802.11無線網路權威指南-網路概論》-- 讀書筆記2筆記
- 《鏡子》《過去已死》閱讀筆記筆記
- 微信MMKV原始碼閱讀隨筆原始碼
- HTML5與CSS3權威指南筆記案例1HTMLCSSS3筆記
- 《JavaScript權威指南第六版》學習筆記-物件JavaScript筆記物件
- 【閱讀筆記:字典】筆記
- gdbOF閱讀筆記筆記