Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
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_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]
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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