getScanner

获取遍历某个HashKey下所有数据的迭代器,用于局部扫描。

  1. public enum FilterType {
  2. FT_NO_FILTER(0),
  3. FT_MATCH_ANYWHERE(1), // match filter string at any position
  4. FT_MATCH_PREFIX(2), // match filter string at prefix
  5. FT_MATCH_POSTFIX(3); // match filter string at postfix
  6. }
  7.  
  8.  
  9. public class ScanOptions {
  10. public int timeoutMillis = 5000; // operation timeout in milli-seconds.
  11. // if timeoutMillis > 0, it is a timeout value for current op,
  12. // else the timeout value in the configuration file will be used.
  13. public int batchSize = 1000; // internal buffer batch size
  14. public boolean startInclusive = true; // if the startSortKey is included
  15. public boolean stopInclusive = false; // if the stopSortKey is included
  16. public FilterType hashKeyFilterType = FilterType.FT_NO_FILTER; // filter type for hash key
  17. public byte[] hashKeyFilterPattern = null; // filter pattern for hash key
  18. public FilterType sortKeyFilterType = FilterType.FT_NO_FILTER; // filter type for sort key
  19. public byte[] sortKeyFilterPattern = null; // filter pattern for sort key
  20. public boolean noValue = false; // only fetch hash_key and sort_key, but not fetch value
  21. }
  22.  
  23.  
  24. /**
  25. * Get Scanner for {startSortKey, stopSortKey} within hashKey
  26. * @param tableName TableHandler name
  27. * @param hashKey used to decide which partition to put this k-v,
  28. * @param startSortKey start sort key scan from
  29. * if null or length == 0, means start from begin
  30. * @param stopSortKey stop sort key scan to
  31. * if null or length == 0, means stop to end
  32. * @param options scan options like endpoint inclusive/exclusive
  33. * @return scanner
  34. * @throws PException
  35. */
  36. 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。