Search in sources :

Example 21 with RowCell

use of com.google.cloud.bigtable.data.v2.models.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 22 with RowCell

use of com.google.cloud.bigtable.data.v2.models.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 23 with RowCell

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

the class TestRowAdapter method adaptResponse_emptyRow.

@Test
public void adaptResponse_emptyRow() {
    Row row = Row.create(ByteString.copyFromUtf8("key"), Collections.<RowCell>emptyList());
    Result result = instance.adaptResponse(row);
    assertEquals(0, result.rawCells().length);
}
Also used : Row(com.google.cloud.bigtable.data.v2.models.Row) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 24 with RowCell

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

the class TestRowAdapter method adaptResponse_oneRow.

@Test
public void adaptResponse_oneRow() {
    String family1 = "family1";
    byte[] family1Bytes = Bytes.toBytes(family1);
    String family2 = "family2";
    byte[] family2Bytes = Bytes.toBytes(family2);
    byte[] qualifier1 = "qualifier1".getBytes();
    byte[] qualifier2 = "qualifier2".getBytes();
    byte[] value1 = "value1".getBytes();
    byte[] value2 = "value2".getBytes();
    byte[] value3 = "value3".getBytes();
    byte[] value4 = "value4".getBytes();
    byte[] value5 = "value5".getBytes();
    ByteString key = ByteString.copyFromUtf8("key");
    final long ts1Micros = 54321L;
    final long ts2Micros = 12345L;
    final long ts1Millis = ts1Micros / 1000;
    final long ts2Millis = ts2Micros / 1000;
    List<String> emptyLabelList = Collections.emptyList();
    ImmutableList<RowCell> rowCells = ImmutableList.of(// First cell.
    RowCell.create(family1, ByteString.copyFrom(qualifier1), ts1Micros, emptyLabelList, ByteString.copyFrom(value1)), // Same family, same column, but different timestamps.
    RowCell.create(family1, ByteString.copyFrom(qualifier1), ts2Micros, emptyLabelList, ByteString.copyFrom(value2)), // Same family, same timestamp, but different column.
    RowCell.create(family1, ByteString.copyFrom(qualifier2), ts1Micros, emptyLabelList, ByteString.copyFrom(value3)), // Same column, same timestamp, but different family.
    RowCell.create(family2, ByteString.copyFrom(qualifier1), ts1Micros, emptyLabelList, ByteString.copyFrom(value4)), // Same timestamp, but different family and column.
    RowCell.create(family2, ByteString.copyFrom(qualifier2), ts1Micros, emptyLabelList, ByteString.copyFrom(value5)), // Contains label, should be ignored.
    RowCell.create(family1, ByteString.copyFrom(qualifier1), ts2Micros, Collections.singletonList("label"), ByteString.copyFrom(value1)));
    Row row = Row.create(key, rowCells);
    Result result = instance.adaptResponse(row);
    assertEquals(5, result.rawCells().length);
    // The duplicate row and label cells have been removed. The timestamp micros get converted to
    // millisecond accuracy.
    byte[] keyArray = ByteStringer.extract(key);
    org.apache.hadoop.hbase.Cell[] expectedCells = new org.apache.hadoop.hbase.Cell[] { new com.google.cloud.bigtable.hbase.adapters.read.RowCell(keyArray, family1Bytes, qualifier1, ts1Millis, value1), new com.google.cloud.bigtable.hbase.adapters.read.RowCell(keyArray, family1Bytes, qualifier1, ts2Millis, value2), new com.google.cloud.bigtable.hbase.adapters.read.RowCell(keyArray, family1Bytes, qualifier2, ts1Millis, value3), new com.google.cloud.bigtable.hbase.adapters.read.RowCell(keyArray, family2Bytes, qualifier1, ts1Millis, value4), new com.google.cloud.bigtable.hbase.adapters.read.RowCell(keyArray, family2Bytes, qualifier2, ts1Millis, value5) };
    assertArrayEquals(expectedCells, result.rawCells());
}
Also used : ByteString(com.google.protobuf.ByteString) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) ByteString(com.google.protobuf.ByteString) Result(org.apache.hadoop.hbase.client.Result) Row(com.google.cloud.bigtable.data.v2.models.Row) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) Test(org.junit.Test)

Example 25 with RowCell

use of com.google.cloud.bigtable.data.v2.models.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

Test (org.junit.Test)22 Row (com.google.cloud.bigtable.data.v2.models.Row)21 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)16 Query (com.google.cloud.bigtable.data.v2.models.Query)10 ByteString (com.google.protobuf.ByteString)10 Result (org.apache.hadoop.hbase.client.Result)10 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)9 RowCell (com.google.cloud.bigtable.hbase.adapters.read.RowCell)8 NotFoundException (com.google.api.gax.rpc.NotFoundException)4 RowAdapter (com.google.cloud.bigtable.data.v2.models.RowAdapter)4 QualifierFilter (org.apache.hadoop.hbase.filter.QualifierFilter)3 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)2 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)2 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)2 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)2 Filters (com.google.cloud.bigtable.data.v2.models.Filters)2 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)2 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)2 Cell (org.apache.hadoop.hbase.Cell)2 Get (org.apache.hadoop.hbase.client.Get)2