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());
}
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();
}
}
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());
}
}
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);
}
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;
}
Aggregations