use of com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation in project java-bigtable-hbase by googleapis.
the class AbstractBigtableTable method checkAndDelete.
/**
* {@inheritDoc}
*/
@Override
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Delete delete) throws IOException {
LOG.trace("checkAndDelete(byte[], byte[], byte[], CompareOp, byte[], Delete)");
ConditionalRowMutation request = new CheckAndMutateUtil.RequestBuilder(hbaseAdapter, row, family).qualifier(qualifier).ifMatches(compareOp, value).withDelete(delete).build();
return checkAndMutate(row, request, "checkAndDelete");
}
use of com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation in project java-bigtable-hbase by googleapis.
the class TestDataClientVeneerApi method testCheckAndMutateRowAsync.
@Test
public void testCheckAndMutateRowAsync() throws Exception {
ConditionalRowMutation conditionalRowM = ConditionalRowMutation.create(TABLE_ID, ROW_KEY);
when(mockDataClient.checkAndMutateRowAsync(conditionalRowM)).thenReturn(ApiFutures.immediateFuture(Boolean.TRUE));
assertTrue(dataClientWrapper.checkAndMutateRowAsync(conditionalRowM).get());
verify(mockDataClient).checkAndMutateRowAsync(conditionalRowM);
}
use of com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation in project java-bigtable-hbase by googleapis.
the class BigtableTable method checkAndMutate.
@Override
public CheckAndMutateBuilder checkAndMutate(byte[] row, byte[] family) {
final CheckAndMutateUtil.RequestBuilder builder = new CheckAndMutateUtil.RequestBuilder(hbaseAdapter, row, family);
return new CheckAndMutateBuilder() {
/**
* {@inheritDoc}
*/
@Override
public CheckAndMutateBuilder qualifier(byte[] qualifier) {
builder.qualifier(qualifier);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public CheckAndMutateBuilder ifNotExists() {
builder.ifNotExists();
return this;
}
/**
* {@inheritDoc}
*/
@Override
public CheckAndMutateBuilder ifMatches(CompareOperator compareOp, byte[] value) {
Preconditions.checkNotNull(compareOp, "compareOp is null");
if (compareOp != CompareOperator.NOT_EQUAL) {
Preconditions.checkNotNull(value, "value is null for compareOperator: " + compareOp);
}
builder.ifMatches(BigtableTable.toCompareOp(compareOp), value);
return this;
}
/**
* {@inheritDoc}
*/
public CheckAndMutateBuilder timeRange(TimeRange timeRange) {
builder.timeRange(timeRange.getMin(), timeRange.getMax());
return this;
}
/**
* {@inheritDoc}
*/
@Override
public boolean thenPut(Put put) throws IOException {
try {
builder.withPut(put);
return call();
} catch (Exception e) {
throw new IOException("Could not CheckAndMutate.thenPut: " + e.getMessage(), e);
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean thenDelete(Delete delete) throws IOException {
try {
builder.withDelete(delete);
return call();
} catch (Exception e) {
throw new IOException("Could not CheckAndMutate.thenDelete: " + e.getMessage(), e);
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean thenMutate(RowMutations rowMutations) throws IOException {
try {
builder.withMutations(rowMutations);
return call();
} catch (Exception e) {
throw new IOException("Could not CheckAndMutate.thenMutate: " + e.getMessage(), e);
}
}
private boolean call() throws IOException {
ConditionalRowMutation conditionalRowMutation = builder.build();
Boolean response = FutureUtil.unwrap(clientWrapper.checkAndMutateRowAsync(conditionalRowMutation));
return CheckAndMutateUtil.wasMutationApplied(conditionalRowMutation, response);
}
};
}
use of com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation 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.ConditionalRowMutation 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();
}
}
Aggregations