HBase:如何在单个扫描操作中指定多个前缀过滤器

HBase: How to specify multiple prefix filters in a single scan operation

我已经使用前缀过滤器获得给定部分行键的扫描结果:

行键示例:123_abc、456_def、789_ghi

var prefix=Bytes.toBytes("123")
var scan = new Scan(prefix)
var prefixFilter = new PrefixFilter(prefix)
scan.setFilter(prefixFilter)
var resultScanner = table.getScanner(scan)

现在,我的问题是如何指定多个前缀过滤器作为扫描操作的输入。结果对象应包含具有给定前缀(例如 123 或 456)的行键值的所有行。

我尝试了以下使用 FilterList 方法的答案,但无法获得所需的结果:

对此(在 Scala 或 Java 中)的任何帮助将不胜感激。谢谢。

请检查这个docs of filter list你可能没有使用正确的选项...

FilterList.Operator.MUST_PASS_ALL (AND) or FilterList.Operator.MUST_PASS_ONE (OR). Since you can use Filter Lists as children of Filter Lists, you can create a hierarchy of filters to be evaluated. FilterList.Operator.MUST_PASS_ALL evaluates lazily: evaluation stops as soon as one filter does not include the KeyValue. FilterList.Operator.MUST_PASS_ONE evaluates non-lazily: all filters are always evaluated. Defaults to FilterList.Operator.MUST_PASS_ALL.

 /* FilterList.Operator.MUST_PASS_ALL by default */
      FilterList allFilters = new FilterList(FilterList.Operator.MUST_PASS_ONE);
      allFilters.addFilter(new PrefixFilter(Bytes.toBytes("123")));
     allFilters.addFilter(new PrefixFilter(Bytes.toBytes("456")));
     allFilters.addFilter(new PrefixFilter(Bytes.toBytes("678")));
    scan.setFilter(allFilters);

    var resultScanner = table.getScanner(scan)

要验证的点:

因为您已经使用了 FilterList,我认为您可能使用了默认的 MUST_PASS_ALL,所有前缀条件都需要 met 可能是它没有给出结果的原因。

上述代码应该可以工作..祝你好运