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;
}
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);
}
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();
}
}
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());
}
}
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");
}
Aggregations