Search in sources :

Example 1 with BigtableExtendedScan

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

the class ScanAdapter method getRangeSet.

private RangeSet<RowKeyWrapper> getRangeSet(Scan scan) {
    if (scan instanceof BigtableExtendedScan) {
        RowSet rowSet = ((BigtableExtendedScan) scan).getRowSet();
        return rowRangeAdapter.rowSetToRangeSet(rowSet);
    } else {
        RangeSet<RowKeyWrapper> rangeSet = TreeRangeSet.create();
        final ByteString startRow = ByteString.copyFrom(scan.getStartRow());
        final ByteString stopRow = ByteString.copyFrom(scan.getStopRow());
        if (scan.isGetScan()) {
            rangeSet.add(Range.singleton(new RowKeyWrapper(startRow)));
        } else {
            final BoundType startBound = (!OPEN_CLOSED_AVAILABLE || scan.includeStartRow()) ? BoundType.CLOSED : BoundType.OPEN;
            final BoundType endBound = (!OPEN_CLOSED_AVAILABLE || !scan.includeStopRow()) ? BoundType.OPEN : BoundType.CLOSED;
            rangeSet.add(rowRangeAdapter.boundedRange(startBound, startRow, endBound, stopRow));
        }
        return rangeSet;
    }
}
Also used : ByteString(com.google.protobuf.ByteString) BoundType(com.google.common.collect.BoundType) RowSet(com.google.bigtable.v2.RowSet) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) BigtableExtendedScan(com.google.cloud.bigtable.hbase.BigtableExtendedScan)

Example 2 with BigtableExtendedScan

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

the class TestScanAdapter method testExtendedScan.

@Test
public void testExtendedScan() {
    byte[] row1 = Bytes.toBytes("row1");
    byte[] row2 = Bytes.toBytes("row2");
    byte[] startRow = Bytes.toBytes(START_KEY);
    byte[] stopRow = Bytes.toBytes(STOP_KEY);
    byte[] prefix = Bytes.toBytes("prefix");
    byte[] prefixEnd = calculatePrefixEnd(prefix);
    BigtableExtendedScan scan = new BigtableExtendedScan();
    scan.addRowKey(row1);
    scan.addRowKey(row2);
    scan.addRange(startRow, stopRow);
    scan.addRangeWithPrefix(prefix);
    scanAdapter.adapt(scan, throwingReadHooks, query);
    RowSet expected = RowSet.newBuilder().addRowKeys(ByteStringer.wrap(row1)).addRowKeys(ByteStringer.wrap(row2)).addRowRanges(toRange(prefix, prefixEnd)).addRowRanges(toRange(startRow, stopRow)).build();
    Assert.assertEquals(expected, query.toProto(requestContext).getRows());
}
Also used : RowSet(com.google.bigtable.v2.RowSet) BigtableExtendedScan(com.google.cloud.bigtable.hbase.BigtableExtendedScan) Test(org.junit.Test)

Aggregations

RowSet (com.google.bigtable.v2.RowSet)2 BigtableExtendedScan (com.google.cloud.bigtable.hbase.BigtableExtendedScan)2 RowKeyWrapper (com.google.cloud.bigtable.hbase.util.RowKeyWrapper)1 BoundType (com.google.common.collect.BoundType)1 ByteString (com.google.protobuf.ByteString)1 Test (org.junit.Test)1