Get the App
SLTechnology News&Howtos  ›  Database  › 

Usage of HBase Filter (2)

Shulou Source: shulou.com Published: 2022-06-01 17:18:48 10月12日 Update

2 、 Dedicated Filters

2.1 SingleColumnValueFilter √

2.2 SingleColumnValueExcludeFilter √

2.3 PrefixFilter √

2.4 PageFilter √

2.5 KeyOnlyFilter √

2.6 FirstKeyOnlyFilter √

2.7 TimestampsFilter x

2.8RandomRowFilter √

2.1 SingleColumnValueFilter

Example: Filter filter=new SingleColumnValueExcludeFilter (Bytes.toBytes (Family), Bytes.toBytes (Qualifier), CompareOp.EQUAL, Bytes.toBytes (Value))

2.2 SingleColumnValueExcludeFilter

Use: contrary to singlecolumnvaluefilter, this shows all the data in the table except the filtered one

Example:

Filter filter=new SingleColumnValueExcludeFilter (Bytes.toBytes (Family), Bytes.toBytes (Qualifier), CompareOp.EQUAL, Bytes.toBytes (Value)); ((SingleColumnValueExcludeFilter) filter) .setFilterIfMissing (true)

Note:! Need to add ((SingleColumnValueExcludeFilter) filter) .setFilterIfMissing (true)

2.3 PrefixFilter and ColumnPrefixFilter

Use: fetch data based on the prefix of Row or Column

Example: Filter filter=new PrefixFilter (Bytes.toBytes ("r"))

Take out all data that RowKey starts with r

2.4 PageFilter

Return the number of page per page by setting pageside

Final byte [] POSTFIX = new byte [] {0x00}; HTable table;try {table = new HTable (config, tablename); Filter filter = new PageFilter (pageside); byte [] lastRow = null; int totalRows = 0; while (true) {Scan scan = new Scan (); scan.setFilter (filter) If (lastRow! = null) {/ / Note that the POSTFIX operation is added here, otherwise 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);} catch (IOException e) {/ / TODO Auto-generated catch blocke.printStackTrace ();}

2.5 KeyOnlyFilter

* generally used in conjunction with other filters

* Filter:KeyOnlyFilter (boolean lenAsVal)

* lenAsVal is false by default, which means that the length of val is not regarded as val. Otherwise, the length of the val will be output as val.

* the key filter can simply set the filtered result set to contain only keys and ignore values. There is an option to save the value of the result set as the length of the value.

Example: Filter filter = new KeyOnlyFilter (false)

2.6 firstkeyonlyFilter

Usage: same as above, but only the first kv of the same key will be returned

2.8 RandomRowFilter

Immediately returns the data of row, and the constructor is

RandomRowFilter (float chance)

Chance values range from 0 to 1.0, and if 1 contains all rows.

Example: Filter filter=new RandomRowFilter (0.5f)

Tags: Example data length result filter same function prefix beginning quantity loop output usage method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information MySQL NVidia Redmi