Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
428 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
samples/snippets/src/main/java/com/example/bigtable/deletes/BatchDeleteExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.bigtable.deletes; | ||
|
||
// [START bigtable_streaming_and_batching] | ||
import com.google.api.gax.batching.Batcher; | ||
import com.google.api.gax.rpc.ServerStream; | ||
import com.google.cloud.bigtable.data.v2.BigtableDataClient; | ||
import com.google.cloud.bigtable.data.v2.models.Query; | ||
import com.google.cloud.bigtable.data.v2.models.Row; | ||
import com.google.cloud.bigtable.data.v2.models.RowMutationEntry; | ||
import java.io.IOException; | ||
|
||
public class BatchDeleteExample { | ||
public void batchDelete(String projectId, String instanceId, String tableId) | ||
throws InterruptedException, IOException { | ||
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) { | ||
try (Batcher<RowMutationEntry, Void> batcher = dataClient.newBulkMutationBatcher(tableId)) { | ||
ServerStream<Row> rows = dataClient.readRows(Query.create(tableId)); | ||
for (Row row : rows) { | ||
batcher.add( | ||
RowMutationEntry.create(row.getKey()).deleteCells("cell_plan", "data_plan_05gb")); | ||
} | ||
// Blocks until mutations are applied on all submitted row entries. | ||
batcher.flush(); | ||
} | ||
} | ||
} | ||
} | ||
// [END bigtable_streaming_and_batching] |
39 changes: 39 additions & 0 deletions
39
samples/snippets/src/main/java/com/example/bigtable/deletes/ConditionalDeleteExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.bigtable.deletes; | ||
|
||
// [START bigtable_delete_check_and_mutate] | ||
import com.google.cloud.bigtable.data.v2.BigtableDataClient; | ||
import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; | ||
import com.google.cloud.bigtable.data.v2.models.Filters; | ||
import com.google.cloud.bigtable.data.v2.models.Mutation; | ||
import java.io.IOException; | ||
|
||
public class ConditionalDeleteExample { | ||
public void conditionalDelete(String projectId, String instanceId, String tableId) | ||
throws IOException { | ||
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) { | ||
Filters.Filter condition = Filters.FILTERS.value().exactMatch("PQ2A.190405.004"); | ||
Mutation mutation = Mutation.create().deleteCells("stats_summary", "os_build"); | ||
dataClient.checkAndMutateRow( | ||
ConditionalRowMutation.create(tableId, "phone#4c410523#20190502") | ||
.condition(condition) | ||
.then(mutation)); | ||
} | ||
} | ||
} | ||
// [END bigtable_delete_check_and_mutate] |
34 changes: 34 additions & 0 deletions
34
samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteColumnCellsExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.bigtable.deletes; | ||
|
||
// [START bigtable_delete_from_column] | ||
import com.google.cloud.bigtable.data.v2.BigtableDataClient; | ||
import com.google.cloud.bigtable.data.v2.models.Mutation; | ||
import com.google.cloud.bigtable.data.v2.models.RowMutation; | ||
import java.io.IOException; | ||
|
||
public class DeleteColumnCellsExample { | ||
public void deleteColumnCells(String projectId, String instanceId, String tableId) | ||
throws IOException { | ||
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) { | ||
Mutation mutation = Mutation.create().deleteCells("cell_plan", "data_plan_01gb"); | ||
dataClient.mutateRow(RowMutation.create(tableId, "phone#4c410523#20190501", mutation)); | ||
} | ||
} | ||
} | ||
// [END bigtable_delete_from_column] |
33 changes: 33 additions & 0 deletions
33
samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteColumnFamilyExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.bigtable.deletes; | ||
|
||
// [START bigtable_delete_column_family] | ||
import com.google.cloud.bigtable.data.v2.BigtableDataClient; | ||
import com.google.cloud.bigtable.data.v2.models.RowMutation; | ||
import java.io.IOException; | ||
|
||
public class DeleteColumnFamilyExample { | ||
public void deleteColumnFamily(String projectId, String instanceId, String tableId) | ||
throws IOException { | ||
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) { | ||
dataClient.mutateRow( | ||
RowMutation.create(tableId, "phone#5c10102#20190501").deleteFamily("stats_summary")); | ||
} | ||
} | ||
} | ||
// [END bigtable_delete_column_family] |
33 changes: 33 additions & 0 deletions
33
samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteRowExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.bigtable.deletes; | ||
|
||
// [START bigtable_delete_from_row] | ||
import com.google.cloud.bigtable.data.v2.BigtableDataClient; | ||
import com.google.cloud.bigtable.data.v2.models.Mutation; | ||
import com.google.cloud.bigtable.data.v2.models.RowMutation; | ||
import java.io.IOException; | ||
|
||
public class DeleteRowExample { | ||
public void deleteRow(String projectId, String instanceId, String tableId) throws IOException { | ||
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) { | ||
Mutation mutation = Mutation.create().deleteRow(); | ||
dataClient.mutateRow(RowMutation.create(tableId, "phone#4c410523#20190501", mutation)); | ||
} | ||
} | ||
} | ||
// [END bigtable_delete_from_row] |
31 changes: 31 additions & 0 deletions
31
samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteTableExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.bigtable.deletes; | ||
|
||
// [START bigtable_delete_table] | ||
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient; | ||
import java.io.IOException; | ||
|
||
public class DeleteTableExample { | ||
public void deleteTable(String projectId, String instanceId, String tableId) throws IOException { | ||
try (BigtableTableAdminClient tableAdminClient = | ||
BigtableTableAdminClient.create(projectId, instanceId)) { | ||
tableAdminClient.deleteTable(tableId); | ||
} | ||
} | ||
} | ||
// [END bigtable_delete_table] |
31 changes: 31 additions & 0 deletions
31
samples/snippets/src/main/java/com/example/bigtable/deletes/DropRowRangeExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.bigtable.deletes; | ||
|
||
// [START bigtable_drop_row_range] | ||
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient; | ||
import java.io.IOException; | ||
|
||
public class DropRowRangeExample { | ||
public void dropRowRange(String projectId, String instanceId, String tableId) throws IOException { | ||
try (BigtableTableAdminClient tableAdminClient = | ||
BigtableTableAdminClient.create(projectId, instanceId)) { | ||
tableAdminClient.dropRowRange(tableId, "phone#4c410523"); | ||
} | ||
} | ||
} | ||
// [END bigtable_drop_row_range] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.