FilterListAdapter extends TypedFilterAdapterBase<FilterList> implements UnsupportedStatusCollector<FilterList> { @Override public RangeSet<RowKeyWrapper> getIndexScanHint(FilterList filter) { final List<RangeSet<RowKeyWrapper>> childHints = collectChildHints(filter); if (childHints.isEmpty()) { return ImmutableRangeSet.of(Range.<RowKeyWrapper>all()); } else if (childHints.size() == 1) { return childHints.get(0); } TreeRangeSet<RowKeyWrapper> result = TreeRangeSet.create(childHints.get(0)); switch (filter.getOperator()) { case MUST_PASS_ONE: for (int i = 1; i < childHints.size(); i++) { result.addAll(childHints.get(i)); } break; case MUST_PASS_ALL: for (int i = 1; i < childHints.size(); i++) { result.removeAll(childHints.get(i).complement()); } break; default: throw new IllegalStateException("Unknown operator: " + filter.getOperator()); } return ImmutableRangeSet.copyOf(result); } FilterListAdapter(FilterAdapter subFilterAdapter); @Override Filters.Filter adapt(FilterAdapterContext context, FilterList filter); @Override FilterSupportStatus isFilterSupported(FilterAdapterContext context, FilterList filter); @Override void collectUnsupportedStatuses(
      FilterAdapterContext context,
      FilterList filter,
      List<FilterSupportStatus> unsupportedStatuses); @Override RangeSet<RowKeyWrapper> getIndexScanHint(FilterList filter);  }
@Test public void testChainedIndexHintIntersection() { FilterAdapter adapter = FilterAdapter.buildAdapter(); PrefixFilter p1 = new PrefixFilter("a".getBytes()); PrefixFilter p2 = new PrefixFilter("abc".getBytes()); FilterList filterList = new FilterList(Operator.MUST_PASS_ALL, p1, p2); RangeSet<RowKeyWrapper> actual = adapter.getIndexScanHint(filterList); RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.of( Range.closedOpen( new RowKeyWrapper(ByteString.copyFromUtf8("abc")), new RowKeyWrapper(ByteString.copyFromUtf8("abd")))); Assert.assertEquals(expected, actual); }
@Test public void testChainedIndexHintDisjointIntersection() { FilterAdapter adapter = FilterAdapter.buildAdapter(); PrefixFilter p1 = new PrefixFilter("a".getBytes()); PrefixFilter p2 = new PrefixFilter("b".getBytes()); FilterList filterList = new FilterList(Operator.MUST_PASS_ALL, p1, p2); RangeSet<RowKeyWrapper> actual = adapter.getIndexScanHint(filterList); RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.of(); Assert.assertEquals(expected, actual); }
@Test public void testInterleavedIndexHintUnion() { FilterAdapter adapter = FilterAdapter.buildAdapter(); PrefixFilter p1 = new PrefixFilter("a".getBytes()); PrefixFilter p2 = new PrefixFilter("abc".getBytes()); FilterList filterList = new FilterList(Operator.MUST_PASS_ONE, p1, p2); RangeSet<RowKeyWrapper> actual = adapter.getIndexScanHint(filterList); RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.of( Range.closedOpen( new RowKeyWrapper(ByteString.copyFromUtf8("a")), new RowKeyWrapper(ByteString.copyFromUtf8("b")))); Assert.assertEquals(expected, actual); }
@Test public void testInterleavedIndexHintDisjointUnion() { FilterAdapter adapter = FilterAdapter.buildAdapter(); PrefixFilter p1 = new PrefixFilter("a".getBytes()); PrefixFilter p2 = new PrefixFilter("c".getBytes()); FilterList filterList = new FilterList(Operator.MUST_PASS_ONE, p1, p2); RangeSet<RowKeyWrapper> actual = adapter.getIndexScanHint(filterList); RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder() .add( Range.closedOpen( new RowKeyWrapper(ByteString.copyFromUtf8("a")), new RowKeyWrapper(ByteString.copyFromUtf8("b")))) .add( Range.closedOpen( new RowKeyWrapper(ByteString.copyFromUtf8("c")), new RowKeyWrapper(ByteString.copyFromUtf8("d")))) .build(); Assert.assertEquals(expected, actual); }