Search in sources :

Example 11 with RowCell

use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.

the class TestBigtableWhileMatchResultScannerAdapter method adapt_oneRow_hasNoMatchingLabels.

@Test
public void adapt_oneRow_hasNoMatchingLabels() throws IOException {
    Result expectedResult = Result.create(ImmutableList.<Cell>of(new RowCell(Bytes.toBytes("key"), Bytes.toBytes("family"), Bytes.toBytes("q"), 10000L, Bytes.toBytes("value"), ImmutableList.of("a-out"))));
    when(mockBigtableResultScanner.next()).thenReturn(expectedResult);
    ResultScanner scanner = adapter.adapt(mockBigtableResultScanner, mockSpan);
    assertNull(scanner.next());
    verify(mockSpan, times(1)).end();
    verify(mockBigtableResultScanner).next();
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 12 with RowCell

use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.

the class TestBatchExecutor method testPartialResults.

@Test
public void testPartialResults() throws Exception {
    when(mockBigtableApi.getDataClient()).thenReturn(mockDataClientWrapper);
    when(mockDataClientWrapper.createBulkRead(isA(String.class))).thenReturn(mockBulkRead);
    byte[] key1 = randomBytes(8);
    byte[] key2 = randomBytes(8);
    Result expected = Result.create(ImmutableList.<org.apache.hadoop.hbase.Cell>of(new RowCell(key1, Bytes.toBytes("cf"), Bytes.toBytes(""), 10, Bytes.toBytes("hi!"), ImmutableList.<String>of())));
    RuntimeException exception = new RuntimeException("Something bad happened");
    when(mockBulkRead.add(any(ByteString.class), any(Filters.Filter.class))).thenReturn(ApiFutures.immediateFuture(expected)).thenReturn(ApiFutures.<Result>immediateFailedFuture(exception));
    List<Get> gets = Arrays.asList(new Get(key1), new Get(key2));
    Object[] results = new Object[2];
    try {
        createExecutor().batch(gets, results);
    } catch (RetriesExhaustedWithDetailsException ignored) {
    }
    assertTrue("first result is a result", results[0] instanceof Result);
    assertTrue(matchesRow(expected).matches(results[0]));
    Assert.assertEquals(exception, results[1]);
}
Also used : RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) ByteString(com.google.protobuf.ByteString) Result(org.apache.hadoop.hbase.client.Result) Filters(com.google.cloud.bigtable.data.v2.models.Filters) RetriesExhaustedWithDetailsException(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) Get(org.apache.hadoop.hbase.client.Get) Test(org.junit.Test)

Example 13 with RowCell

use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.

the class TestBigtableTable method testExists.

@Test
public void testExists() throws IOException {
    Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(Bytes.toBytes("row_key"), Bytes.toBytes("family_name"), Bytes.toBytes("q_name"), 0, ByteString.EMPTY.toByteArray())));
    when(mockBigtableDataClient.readRowAsync(isA(String.class), isA(ByteString.class), isA(Filters.Filter.class))).thenReturn(ApiFutures.immediateFuture(Result.EMPTY_RESULT)).thenReturn(ApiFutures.immediateFuture(expected));
    assertFalse(table.exists(new Get(Bytes.toBytes("empty_row"))));
    // second call is suppose to be present
    assertTrue(table.exists(new Get(Bytes.toBytes("row_key"))));
    verify(mockBigtableDataClient, times(2)).readRowAsync(isA(String.class), isA(ByteString.class), isA(Filters.Filter.class));
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) WhileMatchFilter(org.apache.hadoop.hbase.filter.WhileMatchFilter) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) ByteString(com.google.protobuf.ByteString) Get(org.apache.hadoop.hbase.client.Get) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ByteString(com.google.protobuf.ByteString) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 14 with RowCell

use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.

the class TestBigtableTable method getScanner_withBigtableWhileMatchResultScannerAdapter.

@Test
public void getScanner_withBigtableWhileMatchResultScannerAdapter() throws IOException {
    // A row with no matching label. In case of {@link BigtableWhileMatchResultScannerAdapter} the
    // result is null.
    Result row = Result.create(ImmutableList.<Cell>of(new RowCell(Bytes.toBytes("row_key"), Bytes.toBytes(""), Bytes.toBytes("q_name"), 0, ByteString.EMPTY.toByteArray(), Collections.singletonList("label-in")), new RowCell(Bytes.toBytes("row_key"), Bytes.toBytes(""), Bytes.toBytes("q_name"), 0, Bytes.toBytes("value"))));
    when(mockResultScanner.next()).thenReturn(row);
    QualifierFilter filter = new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("x")));
    WhileMatchFilter whileMatchFilter = new WhileMatchFilter(filter);
    Scan scan = new Scan();
    scan.setFilter(whileMatchFilter);
    org.apache.hadoop.hbase.client.ResultScanner resultScanner = table.getScanner(scan);
    assertNull(resultScanner.next());
    verify(mockBigtableDataClient).readRows(isA(Query.class));
    verify(mockResultScanner).next();
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) WhileMatchFilter(org.apache.hadoop.hbase.filter.WhileMatchFilter) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Scan(org.apache.hadoop.hbase.client.Scan) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator) Result(org.apache.hadoop.hbase.client.Result) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) Test(org.junit.Test)

Example 15 with RowCell

use of com.google.cloud.bigtable.hbase.adapters.read.RowCell in project java-bigtable-hbase by googleapis.

the class TestRowResultAdapter method testDeduplicationLogic.

@Test
public void testDeduplicationLogic() {
    List<String> EMPTY_LABEL = ImmutableList.of();
    ByteString valueForNewQual = ByteString.copyFromUtf8("value for new qualifier");
    ByteString valueForCellWithoutLabel = ByteString.copyFromUtf8("value for Cell without label");
    ByteString valueForCellWithLabel = ByteString.copyFromUtf8("value for cell with labels");
    RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder();
    rowBuilder.startRow(ROW_KEY);
    // new qualifier
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 20000L, EMPTY_LABEL, valueForNewQual.size());
    rowBuilder.cellValue(valueForNewQual);
    rowBuilder.finishCell();
    // same qualifier, same timestamp, without label
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 20000L, EMPTY_LABEL, -1);
    rowBuilder.cellValue(valueForCellWithoutLabel);
    rowBuilder.finishCell();
    // same qualifier, same timestamp, with label
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 20000L, LABELS, -1);
    rowBuilder.cellValue(valueForCellWithLabel);
    rowBuilder.finishCell();
    // same qualifier, different timestamp
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 30000L, EMPTY_LABEL, VALUE.size());
    rowBuilder.cellValue(VALUE);
    rowBuilder.finishCell();
    Result actual = rowBuilder.finishRow();
    assertEquals(3, actual.size());
    Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 20L, valueForNewQual.toByteArray(), EMPTY_LABEL), new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 20L, valueForCellWithLabel.toByteArray(), LABELS), new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 30L, VALUE.toByteArray(), EMPTY_LABEL)));
    assertResult(expected, actual);
}
Also used : ByteString(com.google.protobuf.ByteString) RowAdapter(com.google.cloud.bigtable.data.v2.models.RowAdapter) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) ByteString(com.google.protobuf.ByteString) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

RowCell (com.google.cloud.bigtable.hbase.adapters.read.RowCell)16 Result (org.apache.hadoop.hbase.client.Result)15 Test (org.junit.Test)15 ByteString (com.google.protobuf.ByteString)9 Get (org.apache.hadoop.hbase.client.Get)5 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)5 RowAdapter (com.google.cloud.bigtable.data.v2.models.RowAdapter)4 Cell (org.apache.hadoop.hbase.Cell)3 QualifierFilter (org.apache.hadoop.hbase.filter.QualifierFilter)3 Filters (com.google.cloud.bigtable.data.v2.models.Filters)2 Query (com.google.cloud.bigtable.data.v2.models.Query)2 Scan (org.apache.hadoop.hbase.client.Scan)2 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)2 WhileMatchFilter (org.apache.hadoop.hbase.filter.WhileMatchFilter)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ApiFuture (com.google.api.core.ApiFuture)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RetriesExhaustedWithDetailsException (org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException)1