このFilter
クラスは、必要な機能のフレームワークを構築します。Filter
カスタム フィルターを作成するには、メソッドを拡張して実装する必要がありますaccept(Key k, Value v)
。正規表現に基づいてフィルタリングすることのみを検討している場合は、RegExFilter
.
a を使用するのRegExFilter
は簡単です。次に例を示します。
//first connect to Accumulo
ZooKeeperInstance inst = new ZooKeeperInstance(instanceName, zooServers);
Connector connect = inst.getConnector(user, password);
//initialize a scanner
Scanner scan = connect.createScanner(myTableName, myAuthorizations);
//to use a filter, which is an iterator, you must create an IteratorSetting
//specifying which iterator class you are using
IteratorSetting iter = new IteratorSetting(15, "myFilter", RegExFilter.class);
//next set the regular expressions to match. Here, I want all key/value pairs in
//which the column family begins with "J"
String rowRegex = null;
String colfRegex = "J.*";
String colqRegex = null;
String valueRegex = null;
boolean orFields = false;
RegExFilter.setRegexs(iter, rowRegex, colfRegex, colqRegex, valueRegex, orFields);
//now add the iterator to the scanner, and you're all set
scan.addScanIterator(iter);
この場合、コンストラクターの最初の 2 つのパラメーターiteratorSetting
(優先順位と名前) は関係ありません。上記のコードを追加すると、スキャナーを反復処理すると、正規表現パラメーターに一致するキーと値のペアのみが返されます。