Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: make delete examples consistent with other languages #1710

Merged
merged 2 commits into from Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
billyjacobson marked this conversation as resolved.
Show resolved Hide resolved
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