getScanner
获取遍历某个HashKey下所有数据的迭代器,用于局部扫描。
- public enum FilterType {
- FT_NO_FILTER(0),
- FT_MATCH_ANYWHERE(1), // match filter string at any position
- FT_MATCH_PREFIX(2), // match filter string at prefix
- FT_MATCH_POSTFIX(3); // match filter string at postfix
- }
- public class ScanOptions {
- public int timeoutMillis = 5000; // operation timeout in milli-seconds.
- // if timeoutMillis > 0, it is a timeout value for current op,
- // else the timeout value in the configuration file will be used.
- public int batchSize = 1000; // internal buffer batch size
- public boolean startInclusive = true; // if the startSortKey is included
- public boolean stopInclusive = false; // if the stopSortKey is included
- public FilterType hashKeyFilterType = FilterType.FT_NO_FILTER; // filter type for hash key
- public byte[] hashKeyFilterPattern = null; // filter pattern for hash key
- public FilterType sortKeyFilterType = FilterType.FT_NO_FILTER; // filter type for sort key
- public byte[] sortKeyFilterPattern = null; // filter pattern for sort key
- public boolean noValue = false; // only fetch hash_key and sort_key, but not fetch value
- }
- /**
- * Get Scanner for {startSortKey, stopSortKey} within hashKey
- * @param tableName TableHandler name
- * @param hashKey used to decide which partition to put this k-v,
- * @param startSortKey start sort key scan from
- * if null or length == 0, means start from begin
- * @param stopSortKey stop sort key scan to
- * if null or length == 0, means stop to end
- * @param options scan options like endpoint inclusive/exclusive
- * @return scanner
- * @throws PException
- */
- public PegasusScannerInterface getScanner(String tableName, byte[] hashKey, byte[] startSortKey, byte[] stopSortKey, ScanOptions options) throws PException;
注:
- 参数:需传入TableName、HashKey、StartSortKey、StopSortKey、ScanOptions。
- StartSortKey和StopSortKey用于指定scan的返回,并通过ScanOptions指定区间的开闭。
- 如果StartSortKey为null,表示从头开始;如果StopSortKey为null,表示一直读到尾。
- ScanOptions说明:
- timeoutMillis:从server端读取数据的超时时间,单位毫秒,默认值为5000。
- batchSize:从server端读取数据时每批数据的个数,默认值为1000。
- startInclusive:是否包含StartSortKey,默认为true。
- stopInclusive:是否包含StopSortKey,默认为false。
- hashKeyFilterType:HashKey的过滤类型,包括无过滤、任意位置匹配、前缀匹配和后缀匹配,默认无过滤。
- hashKeyFilterPattern:HashKey的过滤模式串,空串相当于无过滤。
- sortKeyFilterType:SortKey的过滤类型,包括无过滤、任意位置匹配、前缀匹配和后缀匹配,默认无过滤。
- sortKeyFilterPattern:SortKey的过滤模式串,空串相当于无过滤。
- noValue:只返回HashKey和SortKey,不返回Value数据,默认为false。
- 返回值:返回迭代器PegasusScannerInterface。
- 异常:如果出现异常,譬如网络错误、超时错误、服务端错误等,会抛出 PException。