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();
}
}
use of com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation in project java-bigtable by googleapis.
the class BigtableDataClientTests method proxyCheckAndMutateRowTest.
@Test
public void proxyCheckAndMutateRowTest() {
Mockito.when(mockStub.checkAndMutateRowCallable()).thenReturn(mockCheckAndMutateRowCallable);
ConditionalRowMutation mutation = ConditionalRowMutation.create("fake-table", "fake-key").then(Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value"));
bigtableDataClient.checkAndMutateRowAsync(mutation);
Mockito.verify(mockCheckAndMutateRowCallable).futureCall(mutation);
}
use of com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation in project java-bigtable-hbase by googleapis.
the class AbstractBigtableTable method checkAndPut.
/**
* {@inheritDoc}
*/
@Override
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Put put) throws IOException {
LOG.trace("checkAndPut(byte[], byte[], byte[], CompareOp, value, Put)");
ConditionalRowMutation request = new CheckAndMutateUtil.RequestBuilder(hbaseAdapter, row, family).qualifier(qualifier).ifMatches(compareOp, value).withPut(put).build();
return checkAndMutate(row, request, "checkAndPut");
}
use of com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation in project java-bigtable-hbase by googleapis.
the class AbstractBigtableTable method checkAndMutate.
/**
* {@inheritDoc}
*/
@Override
public boolean checkAndMutate(final byte[] row, final byte[] family, final byte[] qualifier, final CompareFilter.CompareOp compareOp, final byte[] value, final RowMutations rm) throws IOException {
LOG.trace("checkAndMutate(byte[], byte[], byte[], CompareOp, byte[], RowMutations)");
ConditionalRowMutation request = new CheckAndMutateUtil.RequestBuilder(hbaseAdapter, row, family).qualifier(qualifier).ifMatches(compareOp, value).withMutations(rm).build();
return checkAndMutate(row, request, "checkAndMutate");
}
use of com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation in project java-bigtable by googleapis.
the class EnhancedBigtableStub method createCheckAndMutateRowCallable.
/**
* Creates a callable chain to handle CheckAndMutateRow RPCs. THe chain will:
*
* <ul>
* <li>Convert {@link ConditionalRowMutation}s into {@link
* com.google.bigtable.v2.CheckAndMutateRowRequest}s.
* <li>Add tracing & metrics.
* </ul>
*/
private UnaryCallable<ConditionalRowMutation, Boolean> createCheckAndMutateRowCallable() {
String methodName = "CheckAndMutateRow";
UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> base = GrpcRawCallableFactory.createUnaryCallable(GrpcCallSettings.<CheckAndMutateRowRequest, CheckAndMutateRowResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getCheckAndMutateRowMethod()).setParamsExtractor(new RequestParamsExtractor<CheckAndMutateRowRequest>() {
@Override
public Map<String, String> extract(CheckAndMutateRowRequest checkAndMutateRowRequest) {
return ImmutableMap.of("table_name", checkAndMutateRowRequest.getTableName(), "app_profile_id", checkAndMutateRowRequest.getAppProfileId());
}
}).build(), settings.checkAndMutateRowSettings().getRetryableCodes());
UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> withStatsHeaders = new StatsHeadersUnaryCallable<>(base);
UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> withHeaderTracer = new HeaderTracerUnaryCallable<>(withStatsHeaders);
UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> retrying = Callables.retrying(withHeaderTracer, settings.checkAndMutateRowSettings(), clientContext);
return createUserFacingUnaryCallable(methodName, new CheckAndMutateRowCallable(retrying, requestContext));
}
Aggregations