Search in sources :

Example 6 with Mutation

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

the class HeaderTracerCallableTest method testGFELatencyCheckAndMutateRow.

@Test
public void testGFELatencyCheckAndMutateRow() throws InterruptedException {
    ConditionalRowMutation mutation = ConditionalRowMutation.create(TABLE_ID, "fake-key").then(Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value"));
    stub.checkAndMutateRowCallable().call(mutation);
    Thread.sleep(WAIT_FOR_METRICS_TIME_MS);
    long latency = StatsTestUtils.getAggregationValueAsLong(localStats, RpcViewConstants.BIGTABLE_GFE_LATENCY_VIEW, ImmutableMap.of(RpcMeasureConstants.BIGTABLE_OP, TagValue.create("Bigtable.CheckAndMutateRow"), RpcMeasureConstants.BIGTABLE_STATUS, TagValue.create("OK")), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID);
    assertThat(latency).isEqualTo(fakeServerTiming.get());
}
Also used : ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation) Test(org.junit.Test)

Example 7 with Mutation

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

the class WriteConditionally method writeConditionally.

public static void writeConditionally(String projectId, String instanceId, String tableId) {
    try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
        long timestamp = System.currentTimeMillis() * 1000;
        String rowkey = "phone#4c410523#20190501";
        Mutation mutation = Mutation.create().setCell(COLUMN_FAMILY_NAME, "os_name", timestamp, "android");
        Filter filter = FILTERS.chain().filter(FILTERS.family().exactMatch(COLUMN_FAMILY_NAME)).filter(FILTERS.qualifier().exactMatch("os_build")).filter(FILTERS.value().regex("PQ2A\\..*"));
        ConditionalRowMutation conditionalRowMutation = ConditionalRowMutation.create(tableId, rowkey).condition(filter).then(mutation);
        boolean success = dataClient.checkAndMutateRow(conditionalRowMutation);
        System.out.printf("Successfully updated row's os_name: %b", success);
    } catch (Exception e) {
        System.out.println("Error during WriteConditionally: \n" + e.toString());
        e.printStackTrace();
    }
}
Also used : ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation) Filter(com.google.cloud.bigtable.data.v2.models.Filters.Filter) Mutation(com.google.cloud.bigtable.data.v2.models.Mutation) ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient)

Example 8 with Mutation

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

the class WriteIncrement method writeIncrement.

public static void writeIncrement(String projectId, String instanceId, String tableId) {
    try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
        // Get an existing row that has a cell with an incrementable value. A value can be incremented
        // if it is encoded as a 64-bit big-endian signed integer.
        String rowkey = "phone#4c410523#20190501";
        ReadModifyWriteRow mutation = ReadModifyWriteRow.create(tableId, rowkey).increment(COLUMN_FAMILY_NAME, "connected_cell", -1);
        Row success = dataClient.readModifyWriteRow(mutation);
        System.out.printf("Successfully updated row %s", success.getKey().toString(Charset.defaultCharset()));
    } catch (Exception e) {
        System.out.println("Error during WriteIncrement: \n" + e.toString());
    }
}
Also used : Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)

Example 9 with Mutation

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

the class BigtableDataClientTest method checkAndMutateRowTest.

@Test
public void checkAndMutateRowTest() {
    Mockito.when(mockStub.checkAndMutateRowCallable()).thenReturn(mockCheckAndMutateRowCallable);
    Mockito.when(mockCheckAndMutateRowCallable.futureCall(ArgumentMatchers.any(ConditionalRowMutation.class))).thenReturn(ApiFutures.immediateFuture(Boolean.TRUE));
    ConditionalRowMutation mutation = ConditionalRowMutation.create("fake-table", "fake-key").then(Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value"));
    bigtableDataClient.checkAndMutateRow(mutation);
    Mockito.verify(mockCheckAndMutateRowCallable).futureCall(mutation);
}
Also used : ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation) Test(org.junit.Test)

Example 10 with Mutation

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

the class HBaseRequestAdapter method adapt.

/**
 * adapt.
 *
 * @param mutation a {@link org.apache.hadoop.hbase.client.Mutation} object.
 * @return a {@link RowMutation} object.
 */
public RowMutation adapt(org.apache.hadoop.hbase.client.Mutation mutation) {
    RowMutation rowMutation = newRowMutationModel(mutation.getRow());
    adapt(mutation, rowMutation);
    return rowMutation;
}
Also used : RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation)

Aggregations

Test (org.junit.Test)10 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)9 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)7 Put (org.apache.hadoop.hbase.client.Put)6 Mutation (com.google.bigtable.v2.Mutation)5 SetCell (com.google.bigtable.v2.Mutation.SetCell)5 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)4 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)3 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)2 Builder (com.google.bigtable.v2.MutateRowsRequest.Builder)2 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)2 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)2 ApiException (com.google.api.gax.rpc.ApiException)1 DeadlineExceededException (com.google.api.gax.rpc.DeadlineExceededException)1 UnavailableException (com.google.api.gax.rpc.UnavailableException)1 MutateRowsResponse (com.google.bigtable.v2.MutateRowsResponse)1 Entry (com.google.bigtable.v2.MutateRowsResponse.Entry)1 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)1 Mutation (com.google.cloud.bigtable.data.v2.models.Mutation)1 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)1