Search in sources :

Example 41 with RowCell

use of com.google.cloud.bigtable.data.v2.models.RowCell in project quarkus-google-cloud-services by quarkiverse.

the class BigtableResource method bigtable.

@GET
public String bigtable() throws IOException {
    BigtableDataSettings.Builder settings = BigtableDataSettings.newBuilder().setProjectId(projectId).setInstanceId(INSTANCE_ID);
    if (authenticated) {
        settings.setCredentialsProvider(credentialsProvider);
    }
    try (BigtableDataClient dataClient = BigtableDataClient.create(settings.build())) {
        // create a row
        RowMutation rowMutation = RowMutation.create(TABLE_ID, "key1").setCell(COLUMN_FAMILY_ID, "test", "value1");
        dataClient.mutateRow(rowMutation);
        Row row = dataClient.readRow(TABLE_ID, "key1");
        StringBuilder cells = new StringBuilder();
        for (RowCell cell : row.getCells()) {
            cells.append(String.format("Family: %s    Qualifier: %s    Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8()));
        }
        return cells.toString();
    }
}
Also used : RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) Row(com.google.cloud.bigtable.data.v2.models.Row) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) GET(javax.ws.rs.GET)

Example 42 with RowCell

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

the class BigtableDataClientTest method existsTest.

@Test
public void existsTest() {
    Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
    Query expectedQuery = Query.create("fake-table").rowKey("fake-row-key").filter(FILTERS.chain().filter(FILTERS.limit().cellsPerRow(1)).filter(FILTERS.value().strip()));
    Row row = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.<RowCell>of());
    Mockito.when(mockReadRowCallable.futureCall(expectedQuery)).thenReturn(ApiFutures.immediateFuture(row)).thenReturn(ApiFutures.<Row>immediateFuture(null));
    boolean result = bigtableDataClient.exists("fake-table", "fake-row-key");
    boolean anotherResult = bigtableDataClient.exists("fake-table", ByteString.copyFromUtf8("fake-row-key"));
    assertThat(result).isTrue();
    assertThat(anotherResult).isFalse();
    Mockito.verify(mockReadRowCallable, Mockito.times(2)).futureCall(expectedQuery);
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Aggregations

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