Search in sources :

Example 1 with KeyOffset

use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.

the class TestSampledRowKeysAdapter method testEmptyRowList.

@Test
public void testEmptyRowList() {
    List<KeyOffset> rowKeys = new ArrayList<>();
    List<HRegionLocation> locations = adapter.adaptResponse(rowKeys);
    Assert.assertEquals(1, locations.size());
    HRegionLocation location = locations.get(0);
    Assert.assertArrayEquals(HConstants.EMPTY_START_ROW, location.getRegionInfo().getStartKey());
    Assert.assertArrayEquals(HConstants.EMPTY_END_ROW, location.getRegionInfo().getEndKey());
    Assert.assertEquals("host", location.getHostname());
    Assert.assertEquals(123, location.getPort());
}
Also used : KeyOffset(com.google.cloud.bigtable.data.v2.models.KeyOffset) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with KeyOffset

use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.

the class TestSampledRowKeysAdapter method testEmptyRow.

@Test
public void testEmptyRow() {
    byte[] rowKey = new byte[0];
    List<KeyOffset> responses = new ArrayList<>();
    responses.add(KeyOffset.create(ByteString.copyFrom(rowKey), 0));
    List<HRegionLocation> locations = adapter.adaptResponse(responses);
    Assert.assertEquals(1, locations.size());
    HRegionLocation location = locations.get(0);
    Assert.assertArrayEquals(HConstants.EMPTY_START_ROW, location.getRegionInfo().getStartKey());
    Assert.assertArrayEquals(HConstants.EMPTY_END_ROW, location.getRegionInfo().getEndKey());
}
Also used : KeyOffset(com.google.cloud.bigtable.data.v2.models.KeyOffset) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with KeyOffset

use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.

the class TestSampledRowKeysAdapter method testOneRow.

@Test
public void testOneRow() {
    byte[] rowKey = Bytes.toBytes("row");
    List<KeyOffset> responses = new ArrayList<>();
    responses.add(KeyOffset.create(ByteString.copyFrom(rowKey), 0));
    List<HRegionLocation> locations = adapter.adaptResponse(responses);
    Assert.assertEquals(2, locations.size());
    HRegionLocation location = locations.get(0);
    Assert.assertArrayEquals(HConstants.EMPTY_START_ROW, location.getRegionInfo().getStartKey());
    Assert.assertArrayEquals(rowKey, location.getRegionInfo().getEndKey());
    location = locations.get(1);
    Assert.assertArrayEquals(rowKey, location.getRegionInfo().getStartKey());
    Assert.assertArrayEquals(HConstants.EMPTY_END_ROW, location.getRegionInfo().getEndKey());
}
Also used : KeyOffset(com.google.cloud.bigtable.data.v2.models.KeyOffset) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with KeyOffset

use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.

the class CloudBigtableIOIntegrationTest method testEstimatedAndSplitForSmallTable.

@Test
@Ignore
public void testEstimatedAndSplitForSmallTable() throws Exception {
    try (Admin admin = connection.getAdmin()) {
        LOG.info("Creating table in testEstimatedAndSplitForSmallTable()");
        TableName tableName = createNewTable(admin);
        try (Table table = connection.getTable(tableName)) {
            table.put(Arrays.asList(new Put(Bytes.toBytes("row1")).addColumn(COLUMN_FAMILY, QUALIFIER1, Bytes.toBytes("1")), new Put(Bytes.toBytes("row2")).addColumn(COLUMN_FAMILY, QUALIFIER1, Bytes.toBytes("2"))));
        }
        LOG.info("getSampleKeys() in testEstimatedAndSplitForSmallTable()");
        try {
            CloudBigtableIO.Source source = (CloudBigtableIO.Source) CloudBigtableIO.read(createScanConfig(tableName));
            List<KeyOffset> sampleRowKeys = source.getSampleRowKeys();
            LOG.info("Creating BoundedSource in testEstimatedAndSplitForSmallTable()");
            long estimatedSizeBytes = source.getEstimatedSizeBytes(null);
            KeyOffset lastSample = sampleRowKeys.get(sampleRowKeys.size() - 1);
            Assert.assertEquals(lastSample.getOffsetBytes(), estimatedSizeBytes);
            LOG.info("Creating Bundles in testEstimatedAndSplitForSmallTable()");
            List<? extends BoundedSource<Result>> bundles = source.split(estimatedSizeBytes / 2 + 1, null);
            // This will be a small table with no splits, so we return HConstants.EMPTY_START_ROW
            // which can't be split.
            LOG.info("Created Bundles in testEstimatedAndSplitForSmallTable()");
            Assert.assertEquals(sampleRowKeys.size() * 2 - 1, bundles.size());
            Assert.assertSame(sampleRowKeys, source.getSampleRowKeys());
        } finally {
            LOG.info("Deleting table in testEstimatedAndSplitForSmallTable()");
            admin.deleteTable(tableName);
            LOG.info("Deleted table in testEstimatedAndSplitForSmallTable()");
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) KeyOffset(com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) BoundedSource(org.apache.beam.sdk.io.BoundedSource) Result(org.apache.hadoop.hbase.client.Result) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with KeyOffset

use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.

the class CloudBigtableIOTest method testSampleRowKeys.

@Test
public void testSampleRowKeys() throws Exception {
    List<KeyOffset> sampleRowKeys = new ArrayList<>();
    int count = (int) (AbstractSource.COUNT_MAX_SPLIT_COUNT * 3 - 5);
    byte[][] keys = Bytes.split("A".getBytes(), "Z".getBytes(), count - 2);
    long tabletSize = 2L * 1024L * 1024L * 1024L;
    long boundary = 0;
    for (byte[] currentKey : keys) {
        boundary += tabletSize;
        try {
            sampleRowKeys.add(KeyOffset.create(ByteString.copyFrom(currentKey), boundary));
        } catch (NoClassDefFoundError e) {
            // This could cause some problems for javadoc or cobertura because of the shading magic we
            // do.
            e.printStackTrace();
            return;
        }
    }
    Source source = (Source) CloudBigtableIO.read(scanConfig);
    source.setSampleRowKeys(sampleRowKeys);
    List<SourceWithKeys> splits = source.getSplits(20000);
    Collections.sort(splits, new Comparator<SourceWithKeys>() {

        @Override
        public int compare(SourceWithKeys o1, SourceWithKeys o2) {
            return ByteStringComparator.INSTANCE.compare(o1.getConfiguration().getStartRowByteString(), o2.getConfiguration().getStartRowByteString());
        }
    });
    Assert.assertTrue(splits.size() <= AbstractSource.COUNT_MAX_SPLIT_COUNT);
    Iterator<SourceWithKeys> iter = splits.iterator();
    SourceWithKeys last = iter.next();
    while (iter.hasNext()) {
        SourceWithKeys current = iter.next();
        Assert.assertTrue(Bytes.equals(current.getConfiguration().getZeroCopyStartRow(), last.getConfiguration().getZeroCopyStopRow()));
        // The last source will have a stop key of empty.
        if (iter.hasNext()) {
            Assert.assertTrue(Bytes.compareTo(current.getConfiguration().getZeroCopyStartRow(), current.getConfiguration().getZeroCopyStopRow()) < 0);
        }
        Assert.assertTrue(current.getEstimatedSize() >= tabletSize);
        last = current;
    }
// check first and last
}
Also used : KeyOffset(com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset) ArrayList(java.util.ArrayList) AbstractSource(com.google.cloud.bigtable.beam.CloudBigtableIO.AbstractSource) Source(com.google.cloud.bigtable.beam.CloudBigtableIO.Source) BoundedSource(org.apache.beam.sdk.io.BoundedSource) SourceWithKeys(com.google.cloud.bigtable.beam.CloudBigtableIO.SourceWithKeys) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 KeyOffset (com.google.cloud.bigtable.data.v2.models.KeyOffset)8 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)6 ArrayList (java.util.ArrayList)5 KeyOffset (com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset)3 BoundedSource (org.apache.beam.sdk.io.BoundedSource)3 TableName (org.apache.hadoop.hbase.TableName)2 Admin (org.apache.hadoop.hbase.client.Admin)2 Put (org.apache.hadoop.hbase.client.Put)2 Result (org.apache.hadoop.hbase.client.Result)2 ApiFuture (com.google.api.core.ApiFuture)1 SampleRowKeysRequest (com.google.bigtable.v2.SampleRowKeysRequest)1 AbstractSource (com.google.cloud.bigtable.beam.CloudBigtableIO.AbstractSource)1 Source (com.google.cloud.bigtable.beam.CloudBigtableIO.Source)1 SourceWithKeys (com.google.cloud.bigtable.beam.CloudBigtableIO.SourceWithKeys)1 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)1 IOException (java.io.IOException)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1