Search in sources :

Example 6 with ConditionalRowMutation

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

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);
}
Also used : ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation) Test(org.junit.Test)

Example 8 with ConditionalRowMutation

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");
}
Also used : ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)

Example 9 with ConditionalRowMutation

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");
}
Also used : ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)

Example 10 with ConditionalRowMutation

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));
}
Also used : HeaderTracerUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable) CheckAndMutateRowResponse(com.google.bigtable.v2.CheckAndMutateRowResponse) StatsHeadersUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable) ByteString(com.google.protobuf.ByteString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest)

Aggregations

ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)11 Test (org.junit.Test)6 CheckAndMutateRowRequest (com.google.bigtable.v2.CheckAndMutateRowRequest)1 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)1 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)1 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)1 Mutation (com.google.cloud.bigtable.data.v2.models.Mutation)1 HeaderTracerUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable)1 StatsHeadersUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable)1 CheckAndMutateUtil (com.google.cloud.bigtable.hbase.adapters.CheckAndMutateUtil)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 Map (java.util.Map)1 CompareOperator (org.apache.hadoop.hbase.CompareOperator)1 Delete (org.apache.hadoop.hbase.client.Delete)1 Put (org.apache.hadoop.hbase.client.Put)1 RowMutations (org.apache.hadoop.hbase.client.RowMutations)1 TimeRange (org.apache.hadoop.hbase.io.TimeRange)1