use of com.google.cloud.bigtable.data.v2.models.BulkMutation 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.BulkMutation in project java-docs-samples by GoogleCloudPlatform.
the class CassandraMigrationCodelab method writeBatch.
public void writeBatch() {
try {
// Timestamp of June 1, 2019 12:00
long timestamp = (long) 1556712000 * 1000;
BulkMutation bulkMutation = BulkMutation.create(tableId).add("tablet#a0b81f74#20190501", Mutation.create().setCell(COLUMN_FAMILY_NAME, "os_name", timestamp, "chromeos").setCell(COLUMN_FAMILY_NAME, "os_build", timestamp, "12155.0.0-rc1")).add("tablet#a0b81f74#20190502", Mutation.create().setCell(COLUMN_FAMILY_NAME, "os_name", timestamp, "chromeos").setCell(COLUMN_FAMILY_NAME, "os_build", timestamp, "12155.0.0-rc6"));
dataClient.bulkMutateRows(bulkMutation);
} catch (Exception e) {
System.out.println("Error during WriteBatch: \n" + e.toString());
}
}
use of com.google.cloud.bigtable.data.v2.models.BulkMutation in project java-bigtable by googleapis.
the class MutateRowsBatchingDescriptorTest method requestBuilderTest.
@Test
public void requestBuilderTest() {
MutateRowsBatchingDescriptor underTest = new MutateRowsBatchingDescriptor();
long timestamp = 10_000L;
BulkMutation bulkMutation = BulkMutation.create("fake-table");
BatchingRequestBuilder<RowMutationEntry, BulkMutation> requestBuilder = underTest.newRequestBuilder(bulkMutation);
requestBuilder.add(RowMutationEntry.create(ROW_KEY).setCell(FAMILY, QUALIFIER, timestamp, VALUE));
requestBuilder.add(RowMutationEntry.create("rowKey-2").setCell("family-2", "q", 20_000L, "some-value"));
BulkMutation actualBulkMutation = requestBuilder.build();
assertThat(actualBulkMutation.toProto(requestContext)).isEqualTo(BulkMutation.create("fake-table").add(ROW_KEY, Mutation.create().setCell(FAMILY, QUALIFIER, timestamp, VALUE)).add("rowKey-2", Mutation.create().setCell("family-2", "q", 20_000L, "some-value")).toProto(requestContext));
}
use of com.google.cloud.bigtable.data.v2.models.BulkMutation in project java-bigtable by googleapis.
the class BulkMutateIT method test.
@Test(timeout = 60 * 1000)
public void test() throws IOException, InterruptedException {
BigtableDataSettings settings = testEnvRule.env().getDataClientSettings();
String rowPrefix = UUID.randomUUID().toString();
// Set target latency really low so it'll trigger adjusting thresholds
BigtableDataSettings.Builder builder = settings.toBuilder().enableBatchMutationLatencyBasedThrottling(2L);
try (BigtableDataClient client = BigtableDataClient.create(builder.build());
BatcherImpl<RowMutationEntry, Void, BulkMutation, Void> batcher = (BatcherImpl<RowMutationEntry, Void, BulkMutation, Void>) client.newBulkMutationBatcher(testEnvRule.env().getTableId())) {
FlowControlEventStats events = batcher.getFlowController().getFlowControlEventStats();
long initialThreashold = Objects.requireNonNull(batcher.getFlowController().getCurrentElementCountLimit());
assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(batcher.getFlowController().getMinElementCountLimit());
assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(batcher.getFlowController().getMaxElementCountLimit());
String familyId = testEnvRule.env().getFamilyId();
long initial = batcher.getFlowController().getCurrentElementCountLimit();
for (long i = 0; i < initial * 3; i++) {
String key = rowPrefix + "test-key" + i;
batcher.add(RowMutationEntry.create(key).setCell(familyId, "qualifier", i));
}
batcher.flush();
assertThat(events.getLastFlowControlEvent()).isNotNull();
// Verify that the threshold is adjusted
assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(initialThreashold);
// Query a key to make sure the write succeeded
Row row = testEnvRule.env().getDataClient().readRowsCallable().first().call(Query.create(testEnvRule.env().getTableId()).rowKey(rowPrefix + "test-key" + initial));
assertThat(row.getCells()).hasSize(1);
}
}
use of com.google.cloud.bigtable.data.v2.models.BulkMutation in project java-bigtable by googleapis.
the class MobileTimeSeriesBaseTest method writePlanData.
public static void writePlanData() throws IOException {
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
BulkMutation bulkMutation = BulkMutation.create(TABLE_ID).add("phone#4c410523#20190501", Mutation.create().setCell(COLUMN_FAMILY_NAME_PLAN, "data_plan_01gb", TIMESTAMP_MINUS_HR, "true").setCell(COLUMN_FAMILY_NAME_PLAN, "data_plan_01gb", TIMESTAMP, "false").setCell(COLUMN_FAMILY_NAME_PLAN, "data_plan_05gb", TIMESTAMP, "true")).add("phone#4c410523#20190502", Mutation.create().setCell(COLUMN_FAMILY_NAME_PLAN, "data_plan_05gb", TIMESTAMP, "true")).add("phone#4c410523#20190505", Mutation.create().setCell(COLUMN_FAMILY_NAME_PLAN, "data_plan_05gb", TIMESTAMP, "true")).add("phone#5c10102#20190501", Mutation.create().setCell(COLUMN_FAMILY_NAME_PLAN, "data_plan_10gb", TIMESTAMP, "true")).add("phone#5c10102#20190502", Mutation.create().setCell(COLUMN_FAMILY_NAME_PLAN, "data_plan_10gb", TIMESTAMP, "true"));
dataClient.bulkMutateRows(bulkMutation);
} catch (IOException e) {
System.out.println("Error during writeTestData: \n" + e.toString());
throw (e);
}
}
Aggregations