Skip to content

Commit

Permalink
docs: make delete examples consistent with other languages (#1710)
Browse files Browse the repository at this point in the history
* docs: make delete examples consistent with other languages

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
billyjacobson and gcf-owl-bot[bot] committed Apr 13, 2023
1 parent ce0799b commit 2d80188
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 22 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -504,9 +504,10 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-bigtable/tree
| Write Simple | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/WriteSimple.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/WriteSimple.java) |
| Batch Delete Example | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/deletes/BatchDeleteExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/deletes/BatchDeleteExample.java) |
| Conditional Delete Example | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/deletes/ConditionalDeleteExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/deletes/ConditionalDeleteExample.java) |
| Delete Column Cells Example | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteColumnCellsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteColumnCellsExample.java) |
| Delete Column Family Example | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteColumnFamilyExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteColumnFamilyExample.java) |
| Delete Row Example | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteRowExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteRowExample.java) |
| Delete From Column Example | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteFromColumnExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteFromColumnExample.java) |
| Delete From Column Family Example | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteFromColumnFamilyExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteFromColumnFamilyExample.java) |
| Delete From Row Example | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteFromRowExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteFromRowExample.java) |
| Delete Table Example | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteTableExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/deletes/DeleteTableExample.java) |
| Drop Row Range Example | [source code](https://github.com/googleapis/java-bigtable/blob/main/samples/snippets/src/main/java/com/example/bigtable/deletes/DropRowRangeExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigtable&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigtable/deletes/DropRowRangeExample.java) |

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Google LLC
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,16 +17,18 @@
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 com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient;
import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest;
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"));
public void deleteColumnFamily(
String projectId, String instanceId, String tableId, String columnFamily) throws IOException {
try (BigtableTableAdminClient tableAdminClient =
BigtableTableAdminClient.create(projectId, instanceId)) {
ModifyColumnFamiliesRequest modifyColumnFamiliesRequest =
ModifyColumnFamiliesRequest.of(tableId).dropFamily(columnFamily);
tableAdminClient.modifyFamilies(modifyColumnFamiliesRequest);
}
}
}
Expand Down
Expand Up @@ -22,8 +22,8 @@
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)
public class DeleteFromColumnExample {
public void deleteFromColumnCells(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");
Expand Down
@@ -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_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 DeleteFromColumnFamilyExample {
public void deleteFromColumnFamily(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_from_column_family]
Expand Up @@ -22,8 +22,9 @@
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 {
public class DeleteFromRowExample {
public void deleteFromRow(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));
Expand Down
Expand Up @@ -63,8 +63,8 @@ public void test1_testDeleteFromColumn() throws IOException {

Truth.assertThat(cells).isNotEmpty();

DeleteColumnCellsExample deleteColumnCellsExample = new DeleteColumnCellsExample();
deleteColumnCellsExample.deleteColumnCells(projectId, instanceId, TABLE_ID);
DeleteFromColumnExample deleteFromColumnExample = new DeleteFromColumnExample();
deleteFromColumnExample.deleteFromColumnCells(projectId, instanceId, TABLE_ID);
row = bigtableDataClient.readRow(TABLE_ID, rowKey);
List<RowCell> cellsAfterDelete = row.getCells(COLUMN_FAMILY_NAME_PLAN, qualifier);

Expand All @@ -78,8 +78,8 @@ public void test2_testDeleteFromRow() throws IOException {

Truth.assertThat(row).isNotNull();

DeleteRowExample deleteRowExample = new DeleteRowExample();
deleteRowExample.deleteRow(projectId, instanceId, TABLE_ID);
DeleteFromRowExample deleteFromRowExample = new DeleteFromRowExample();
deleteFromRowExample.deleteFromRow(projectId, instanceId, TABLE_ID);
row = bigtableDataClient.readRow(TABLE_ID, rowKey);

Truth.assertThat(row).isNull();
Expand Down Expand Up @@ -143,23 +143,38 @@ public void test5_testDropRowRange() throws IOException {
}

@Test
public void test6_testDeleteColumnFamily() throws IOException {
public void test6_testDeleteFromColumnFamily() throws IOException {
String rowKey = "phone#5c10102#20190501";
Row row = bigtableDataClient.readRow(TABLE_ID, rowKey);
List<RowCell> cells = row.getCells(COLUMN_FAMILY_NAME_STATS);

Truth.assertThat(cells).isNotEmpty();

DeleteColumnFamilyExample deleteColumnFamilyExample = new DeleteColumnFamilyExample();
deleteColumnFamilyExample.deleteColumnFamily(projectId, instanceId, TABLE_ID);
DeleteFromColumnFamilyExample deleteFromColumnFamilyExample =
new DeleteFromColumnFamilyExample();
deleteFromColumnFamilyExample.deleteFromColumnFamily(projectId, instanceId, TABLE_ID);
row = bigtableDataClient.readRow(TABLE_ID, rowKey);
List<RowCell> cellsAfterDelete = row.getCells(COLUMN_FAMILY_NAME_STATS);

Truth.assertThat(cellsAfterDelete).isEmpty();
}

@Test
public void test7_testDeleteTable() throws IOException {
public void test7_testDeleteColumnFamily() throws IOException {
try (BigtableTableAdminClient tableAdminClient =
BigtableTableAdminClient.create(projectId, instanceId)) {
Truth.assertThat(tableAdminClient.getTable(TABLE_ID).getColumnFamilies().size()).isEqualTo(2);

DeleteColumnFamilyExample deleteColumnFamilyExample = new DeleteColumnFamilyExample();
deleteColumnFamilyExample.deleteColumnFamily(
projectId, instanceId, TABLE_ID, COLUMN_FAMILY_NAME_STATS);

Truth.assertThat(tableAdminClient.getTable(TABLE_ID).getColumnFamilies().size()).isEqualTo(1);
}
}

@Test
public void test8_testDeleteTable() throws IOException {
try (BigtableTableAdminClient tableAdminClient =
BigtableTableAdminClient.create(projectId, instanceId)) {
Truth.assertThat(tableAdminClient.exists(TABLE_ID)).isTrue();
Expand Down

0 comments on commit 2d80188

Please sign in to comment.