Search in sources :

Example 16 with RowMutation

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

the class HelloWorld method writeToTable.

/**
 * Demonstrates how to write some rows to a table.
 */
public void writeToTable() {
    // [START bigtable_hw_write_rows]
    try {
        System.out.println("\nWriting some greetings to the table");
        String[] names = { "World", "Bigtable", "Java" };
        for (int i = 0; i < names.length; i++) {
            String greeting = "Hello " + names[i] + "!";
            RowMutation rowMutation = RowMutation.create(tableId, ROW_KEY_PREFIX + i).setCell(COLUMN_FAMILY, COLUMN_QUALIFIER_NAME, names[i]).setCell(COLUMN_FAMILY, COLUMN_QUALIFIER_GREETING, greeting);
            dataClient.mutateRow(rowMutation);
            System.out.println(greeting);
        }
    } catch (NotFoundException e) {
        System.err.println("Failed to write to non-existent table: " + e.getMessage());
    }
// [END bigtable_hw_write_rows]
}
Also used : RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Example 17 with RowMutation

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

the class WriteSimple method writeSimple.

public static void writeSimple(String projectId, String instanceId, String tableId) {
    try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
        long timestamp = System.currentTimeMillis() * 1000;
        String rowkey = "phone#4c410523#20190501";
        RowMutation rowMutation = RowMutation.create(tableId, rowkey).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_cell".getBytes()), timestamp, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_wifi".getBytes()), timestamp, 1).setCell(COLUMN_FAMILY_NAME, "os_build", timestamp, "PQ2A.190405.003");
        dataClient.mutateRow(rowMutation);
        System.out.printf("Successfully wrote row %s", rowkey);
    } catch (Exception e) {
        System.out.println("Error during WriteSimple: \n" + e.toString());
    }
}
Also used : RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) ByteString(com.google.protobuf.ByteString) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient)

Example 18 with RowMutation

use of com.google.cloud.bigtable.data.v2.models.RowMutation in project java-docs-samples by GoogleCloudPlatform.

the class CassandraMigrationCodelab method update2.

public void update2() {
    try {
        // Timestamp of June 1, 2019 12:30
        long timestamp = (long) 1556713800 * 1000;
        String rowKey = "phone#4c410523#20190501";
        ByteString zero = ByteString.copyFrom(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 });
        RowMutation rowMutation = RowMutation.create(tableId, rowKey).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_cell".getBytes()), timestamp, zero);
        dataClient.mutateRow(rowMutation);
    } catch (Exception e) {
        System.out.println("Error during update2: \n" + e.toString());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) ByteString(com.google.protobuf.ByteString)

Example 19 with RowMutation

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

the class HBaseRequestAdapter method adaptEntry.

/**
 * adaptEntry.
 *
 * @param put a {@link Put} object.
 * @return a {@link RowMutationEntry} object.
 */
public RowMutationEntry adaptEntry(Put put) {
    RowMutationEntry rowMutation = buildRowMutationEntry(put.getRow());
    adapt(put, rowMutation);
    return rowMutation;
}
Also used : RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry)

Example 20 with RowMutation

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

the class HBaseRequestAdapter method adapt.

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

Aggregations

RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)23 ByteString (com.google.protobuf.ByteString)8 Test (org.junit.Test)7 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)5 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)5 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)3 ApiFuture (com.google.api.core.ApiFuture)2 UnaryCallable (com.google.api.gax.rpc.UnaryCallable)2 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)2 ApiFutures (com.google.api.core.ApiFutures)1 Batcher (com.google.api.gax.batching.Batcher)1 BatcherImpl (com.google.api.gax.batching.BatcherImpl)1 BatchingDescriptor (com.google.api.gax.batching.BatchingDescriptor)1 BatchingSettings (com.google.api.gax.batching.BatchingSettings)1 FlowControlSettings (com.google.api.gax.batching.FlowControlSettings)1 NotFoundException (com.google.api.gax.rpc.NotFoundException)1 ResponseObserver (com.google.api.gax.rpc.ResponseObserver)1 ServerStreamingCallable (com.google.api.gax.rpc.ServerStreamingCallable)1 CheckAndMutateRowRequest (com.google.bigtable.v2.CheckAndMutateRowRequest)1 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)1