Search in sources :

Example 6 with RowKeyWrapper

use of com.google.cloud.bigtable.hbase.util.RowKeyWrapper 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)

Example 7 with RowKeyWrapper

use of com.google.cloud.bigtable.hbase.util.RowKeyWrapper in project java-bigtable-hbase by googleapis.

the class TestFilterListAdapter method testChainedIndexHintDisjointIntersection.

@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);
}
Also used : PrefixFilter(org.apache.hadoop.hbase.filter.PrefixFilter) FilterList(org.apache.hadoop.hbase.filter.FilterList) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) Test(org.junit.Test)

Example 8 with RowKeyWrapper

use of com.google.cloud.bigtable.hbase.util.RowKeyWrapper in project java-bigtable-hbase by googleapis.

the class TestFilterListAdapter method testChainedIndexHintIntersection.

@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);
}
Also used : PrefixFilter(org.apache.hadoop.hbase.filter.PrefixFilter) FilterList(org.apache.hadoop.hbase.filter.FilterList) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) Test(org.junit.Test)

Example 9 with RowKeyWrapper

use of com.google.cloud.bigtable.hbase.util.RowKeyWrapper in project java-bigtable-hbase by googleapis.

the class TestMultiRowRangeAdapter method testOpenClosedSingle.

@Test
public void testOpenClosedSingle() throws IOException {
    MultiRowRangeFilter filter = new MultiRowRangeFilter(Collections.singletonList(new RowRange("cc", false, "ee", true)));
    Filters.Filter adaptedFilter = adapter.adapt(context, filter);
    Assert.assertEquals(unaffectedRowFilter, adaptedFilter);
    RangeSet<RowKeyWrapper> indexScanHint = adapter.getIndexScanHint(filter);
    RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.of(Range.openClosed(new RowKeyWrapper(ByteString.copyFromUtf8("cc")), new RowKeyWrapper(ByteString.copyFromUtf8("ee"))));
    Assert.assertEquals(expected, indexScanHint);
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) MultiRowRangeFilter(org.apache.hadoop.hbase.filter.MultiRowRangeFilter) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) Test(org.junit.Test)

Example 10 with RowKeyWrapper

use of com.google.cloud.bigtable.hbase.util.RowKeyWrapper in project java-bigtable-hbase by googleapis.

the class TestRowRangeAdapter method testGreaterThan.

@Test
public void testGreaterThan() {
    ByteString key = ByteString.copyFromUtf8("hi");
    RowSet in = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyOpen(key)).build();
    RangeSet<RowKeyWrapper> out = adapter.rowSetToRangeSet(in);
    RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.greaterThan(new RowKeyWrapper(key))).build();
    assertEquals(expected, out);
    adapter.rangeSetToByteStringRange(out, query);
    assertEquals(in, query.toProto(requestContext).getRows());
}
Also used : ByteString(com.google.protobuf.ByteString) RowSet(com.google.bigtable.v2.RowSet) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) Test(org.junit.Test)

Aggregations

RowKeyWrapper (com.google.cloud.bigtable.hbase.util.RowKeyWrapper)34 Test (org.junit.Test)28 RowSet (com.google.bigtable.v2.RowSet)14 ByteString (com.google.protobuf.ByteString)12 Filters (com.google.cloud.bigtable.data.v2.models.Filters)9 MultiRowRangeFilter (org.apache.hadoop.hbase.filter.MultiRowRangeFilter)9 RowRange (org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange)9 PrefixFilter (org.apache.hadoop.hbase.filter.PrefixFilter)5 FilterList (org.apache.hadoop.hbase.filter.FilterList)4 BigtableExtendedScan (com.google.cloud.bigtable.hbase.BigtableExtendedScan)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 BoundType (com.google.common.collect.BoundType)2 Filter (org.apache.hadoop.hbase.filter.Filter)2 ChainFilter (com.google.cloud.bigtable.data.v2.models.Filters.ChainFilter)1 InterleaveFilter (com.google.cloud.bigtable.data.v2.models.Filters.InterleaveFilter)1 ByteStringRange (com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange)1 FilterAdapter (com.google.cloud.bigtable.hbase.adapters.filters.FilterAdapter)1 FilterAdapterContext (com.google.cloud.bigtable.hbase.adapters.filters.FilterAdapterContext)1 ImmutableRangeSet (com.google.common.collect.ImmutableRangeSet)1 RangeSet (com.google.common.collect.RangeSet)1