Search in sources :

Example 1 with FilterAdapter

use of com.google.cloud.bigtable.hbase.adapters.filters.FilterAdapter in project java-bigtable-hbase by googleapis.

the class TestScanAdapter method testNarrowedScan.

@Test
public void testNarrowedScan() throws IOException {
    FilterAdapter filterAdapter = Mockito.mock(FilterAdapter.class);
    ScanAdapter scanAdapter = new ScanAdapter(filterAdapter, new RowRangeAdapter());
    Filter fakeFilter = new FilterBase() {

        @Override
        public ReturnCode filterKeyValue(Cell v) throws IOException {
            return ReturnCode.INCLUDE;
        }
    };
    RangeSet<RowKeyWrapper> rangeSet = ImmutableRangeSet.of(Range.closedOpen(new RowKeyWrapper(ByteString.copyFromUtf8("b")), new RowKeyWrapper(ByteString.copyFromUtf8("d"))));
    Mockito.when(filterAdapter.getIndexScanHint(any(Filter.class))).thenReturn(rangeSet);
    Mockito.when(filterAdapter.adaptFilter(any(FilterAdapterContext.class), eq(fakeFilter))).thenReturn(Optional.of(Filters.FILTERS.pass()));
    Scan scan = new Scan().withStartRow("a".getBytes()).withStopRow("z".getBytes()).setFilter(fakeFilter);
    scanAdapter.adapt(scan, throwingReadHooks, query);
    Assert.assertEquals(RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyClosed(ByteString.copyFromUtf8("b")).setEndKeyOpen(ByteString.copyFromUtf8("d"))).build(), query.toProto(requestContext).getRows());
}
Also used : Filter(org.apache.hadoop.hbase.filter.Filter) FilterAdapter(com.google.cloud.bigtable.hbase.adapters.filters.FilterAdapter) FilterAdapterContext(com.google.cloud.bigtable.hbase.adapters.filters.FilterAdapterContext) BigtableExtendedScan(com.google.cloud.bigtable.hbase.BigtableExtendedScan) Scan(org.apache.hadoop.hbase.client.Scan) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) Cell(org.apache.hadoop.hbase.Cell) FilterBase(org.apache.hadoop.hbase.filter.FilterBase) Test(org.junit.Test)

Aggregations

BigtableExtendedScan (com.google.cloud.bigtable.hbase.BigtableExtendedScan)1 FilterAdapter (com.google.cloud.bigtable.hbase.adapters.filters.FilterAdapter)1 FilterAdapterContext (com.google.cloud.bigtable.hbase.adapters.filters.FilterAdapterContext)1 RowKeyWrapper (com.google.cloud.bigtable.hbase.util.RowKeyWrapper)1 Cell (org.apache.hadoop.hbase.Cell)1 Scan (org.apache.hadoop.hbase.client.Scan)1 Filter (org.apache.hadoop.hbase.filter.Filter)1 FilterBase (org.apache.hadoop.hbase.filter.FilterBase)1 Test (org.junit.Test)1