Search in sources :

Example 11 with BulkMutation

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

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

Example 13 with BulkMutation

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

Example 14 with BulkMutation

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);
    }
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) FlowControlEventStats(com.google.api.gax.batching.FlowControlEventStats) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) Row(com.google.cloud.bigtable.data.v2.models.Row) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BatcherImpl(com.google.api.gax.batching.BatcherImpl) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Test(org.junit.Test)

Example 15 with BulkMutation

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);
    }
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) IOException(java.io.IOException) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient)

Aggregations

BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)16 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)9 Test (org.junit.Test)6 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)4 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)4 Row (com.google.cloud.bigtable.data.v2.models.Row)4 IOException (java.io.IOException)4 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)3 Before (org.junit.Before)3 ApiFuture (com.google.api.core.ApiFuture)2 Query (com.google.cloud.bigtable.data.v2.models.Query)2 ByteString (com.google.protobuf.ByteString)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 ApiFutures (com.google.api.core.ApiFutures)1 Batcher (com.google.api.gax.batching.Batcher)1 BatcherImpl (com.google.api.gax.batching.BatcherImpl)1 FlowControlEventStats (com.google.api.gax.batching.FlowControlEventStats)1 ResponseObserver (com.google.api.gax.rpc.ResponseObserver)1 ServerStreamingCallable (com.google.api.gax.rpc.ServerStreamingCallable)1