Search in sources :

Example 51 with Row

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

the class BigtableBackupIT method createAndPopulateTestTable.

private static Table createAndPopulateTestTable(BigtableTableAdminClient tableAdmin, BigtableDataClient dataClient) throws InterruptedException {
    String tableId = PrefixGenerator.newPrefix("BigtableBackupIT#createAndPopulateTestTable");
    Table testTable = tableAdmin.createTable(CreateTableRequest.of(tableId).addFamily("cf1"));
    // Populate test data.
    byte[] rowBytes = new byte[1024];
    Random random = new Random();
    random.nextBytes(rowBytes);
    try (Batcher<RowMutationEntry, Void> batcher = dataClient.newBulkMutationBatcher(tableId)) {
        for (int i = 0; i < 10; i++) {
            batcher.add(RowMutationEntry.create("test-row-" + i).setCell("cf1", ByteString.EMPTY, ByteString.copyFrom(rowBytes)));
        }
    }
    return testTable;
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) Random(java.util.Random) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) ByteString(com.google.protobuf.ByteString)

Example 52 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project native-image-support-java by GoogleCloudPlatform.

the class BigTableSampleApplication method insertData.

private static void insertData(BigtableDataClient client, String tableId) {
    long timestamp = System.currentTimeMillis() * 1000;
    String rowKey = String.format("phone#%d", timestamp);
    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");
    client.mutateRow(rowMutation);
    System.out.println("Successfully wrote row: " + rowKey);
}
Also used : RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) ByteString(com.google.protobuf.ByteString)

Example 53 with Row

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

the class Memcached method memcachedBigtable.

public static void memcachedBigtable(String projectId, String instanceId, String tableId, String discoveryEndpoint) {
    try {
        MemcachedClient mcc = new MemcachedClient(new InetSocketAddress(discoveryEndpoint, 11211));
        System.out.println("Connected to Memcached successfully");
        // Get value from cache
        String rowkey = "phone#4c410523#20190501";
        String columnFamily = "stats_summary";
        String column = "os_build";
        String cacheKey = String.format("%s:%s:%s", rowkey, columnFamily, column);
        Object value = mcc.get(cacheKey);
        if (value != null) {
            System.out.println("Value fetched from cache: " + value);
        } else {
            System.out.println("didn't get value from cache");
            // Get data from Bigtable source and add to cache for 30 minutes.
            try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
                Row row = dataClient.readRow(tableId, rowkey);
                String cellValue = row.getCells(columnFamily, column).get(0).getValue().toStringUtf8();
                System.out.println("got data from bt " + cellValue);
                // Set data into memcached server.
                mcc.set(cacheKey, 30 * 60, cellValue);
                System.out.println("Value fetched from Bigtable: " + cellValue);
            } catch (Exception e) {
                System.out.println("Could not set cache value.");
                e.printStackTrace();
            }
        }
        mcc.shutdown();
    } catch (Exception e) {
        System.out.println("Could not get cache value.");
        e.printStackTrace();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MemcachedClient(net.spy.memcached.MemcachedClient) Row(com.google.cloud.bigtable.data.v2.models.Row) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient)

Example 54 with Row

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

the class CassandraMigrationCodelab method deleteMultiple.

public void deleteMultiple() {
    try {
        Query query = Query.create(tableId).prefix("tablet#a0b81f7");
        ServerStream<Row> rowStream = dataClient.readRows(query);
        BulkMutation bulkMutation = BulkMutation.create(tableId);
        for (Row row : rowStream) {
            bulkMutation.add(row.getKey(), Mutation.create().deleteRow());
        }
        dataClient.bulkMutateRows(bulkMutation);
    } catch (Exception e) {
        System.out.println("Error during DeleteMultiple: \n" + e.toString());
    }
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row)

Example 55 with Row

use of com.google.cloud.bigtable.data.v2.models.Row 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)

Aggregations

Row (com.google.cloud.bigtable.data.v2.models.Row)71 Test (org.junit.Test)64 Query (com.google.cloud.bigtable.data.v2.models.Query)34 ByteString (com.google.protobuf.ByteString)28 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)26 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)19 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)19 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)13 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)11 IOException (java.io.IOException)10 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)9 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)7 Put (org.apache.hadoop.hbase.client.Put)7 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)6 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)5 Mutation (com.google.bigtable.v2.Mutation)5 SetCell (com.google.bigtable.v2.Mutation.SetCell)5 NotFoundException (com.google.api.gax.rpc.NotFoundException)4 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)4 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)4