Search in sources :

Example 11 with RowCell

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

the class BigtableDataClientTest method readRowStrFilterTest.

@Test
public void readRowStrFilterTest() {
    Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
    // Build the filter expression
    Filter filter = FILTERS.chain().filter(FILTERS.qualifier().regex("prefix.*")).filter(FILTERS.limit().cellsPerRow(10));
    Row expectedRow = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.<RowCell>of());
    Mockito.when(mockReadRowCallable.futureCall(Query.create("fake-table").rowKey("fake-row-key").filter(filter))).thenReturn(ApiFutures.immediateFuture(expectedRow));
    Row actualRow = bigtableDataClient.readRow("fake-table", "fake-row-key", filter);
    assertThat(actualRow).isEqualTo(expectedRow);
}
Also used : Filter(com.google.cloud.bigtable.data.v2.models.Filters.Filter) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 12 with RowCell

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

the class BigtableDataClientTest method readModifyWriteRowTest.

@Test
public void readModifyWriteRowTest() {
    Mockito.when(mockStub.readModifyWriteRowCallable()).thenReturn(mockReadModifyWriteRowCallable);
    Mockito.when(mockReadModifyWriteRowCallable.futureCall(ArgumentMatchers.any(ReadModifyWriteRow.class))).thenReturn(ApiFutures.immediateFuture(Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.<RowCell>emptyList())));
    ReadModifyWriteRow request = ReadModifyWriteRow.create("fake-table", "some-key").append("fake-family", "fake-qualifier", "suffix");
    bigtableDataClient.readModifyWriteRow(request);
    Mockito.verify(mockReadModifyWriteRowCallable).futureCall(request);
}
Also used : ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 13 with RowCell

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

the class ReadRowsMergingAcceptanceTest method test.

@Test
public void test() throws Exception {
    List<ReadRowsResponse> responses = Lists.newArrayList();
    // Convert the chunks into a single ReadRowsResponse
    for (CellChunk chunk : testCase.getChunksList()) {
        ReadRowsResponse.Builder responseBuilder = ReadRowsResponse.newBuilder();
        responseBuilder.addChunks(chunk);
        responses.add(responseBuilder.build());
    }
    // Wrap the responses in a callable
    ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> source = new ServerStreamingStashCallable<>(responses);
    RowMergingCallable<Row> mergingCallable = new RowMergingCallable<>(source, new DefaultRowAdapter());
    // Invoke the callable to get the merged rows
    ServerStream<Row> stream = mergingCallable.call(ReadRowsRequest.getDefaultInstance());
    // Read all of the rows and transform them into logical cells
    List<ReadRowsTest.Result> actualResults = Lists.newArrayList();
    Exception error = null;
    try {
        for (Row row : stream) {
            for (RowCell cell : row.getCells()) {
                actualResults.add(ReadRowsTest.Result.newBuilder().setRowKeyBytes(row.getKey()).setFamilyName(cell.getFamily()).setQualifierBytes(cell.getQualifier()).setTimestampMicros(cell.getTimestamp()).setValueBytes(cell.getValue()).setLabel(cell.getLabels().isEmpty() ? "" : cell.getLabels().get(0)).build());
            }
        }
    } catch (Exception e) {
        error = e;
    }
    // Verify the results
    if (expectsError(testCase)) {
        assertThat(error).isNotNull();
    } else {
        if (error != null) {
            throw error;
        }
    }
    assertThat(getNonExceptionResults(testCase)).isEqualTo(actualResults);
}
Also used : CellChunk(com.google.bigtable.v2.ReadRowsResponse.CellChunk) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) IOException(java.io.IOException) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadRowsTest(com.google.cloud.conformance.bigtable.v2.TestDefinition.ReadRowsTest) Test(org.junit.Test)

Example 14 with RowCell

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

the class RowMergingCallableTest method scanMarker.

@Test
public void scanMarker() {
    FakeStreamingApi.ServerStreamingStashCallable<ReadRowsRequest, ReadRowsResponse> inner = new ServerStreamingStashCallable<>(Lists.newArrayList(// send a scan marker
    ReadRowsResponse.newBuilder().setLastScannedRowKey(ByteString.copyFromUtf8("key1")).build()));
    RowMergingCallable<Row> rowMergingCallable = new RowMergingCallable<>(inner, new DefaultRowAdapter());
    List<Row> results = rowMergingCallable.all().call(ReadRowsRequest.getDefaultInstance());
    Truth.assertThat(results).containsExactly(Row.create(ByteString.copyFromUtf8("key1"), Lists.<RowCell>newArrayList()));
}
Also used : FakeStreamingApi(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) Test(org.junit.Test)

Example 15 with RowCell

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

the class HelloWorld method readSpecificCells.

/**
 * Demonstrates how to access specific cells by family and qualifier.
 */
public List<RowCell> readSpecificCells() {
    // [START bigtable_hw_get_by_key]
    try {
        System.out.println("\nReading specific cells by family and qualifier");
        Row row = dataClient.readRow(tableId, ROW_KEY_PREFIX + 0);
        System.out.println("Row: " + row.getKey().toStringUtf8());
        List<RowCell> cells = row.getCells(COLUMN_FAMILY, COLUMN_QUALIFIER_NAME);
        for (RowCell cell : cells) {
            System.out.printf("Family: %s    Qualifier: %s    Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
        }
        return cells;
    } catch (NotFoundException e) {
        System.err.println("Failed to read from a non-existent table: " + e.getMessage());
        return null;
    }
// [END bigtable_hw_get_by_key]
}
Also used : RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) NotFoundException(com.google.api.gax.rpc.NotFoundException) Row(com.google.cloud.bigtable.data.v2.models.Row)

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