Locate a row by its primary key and remove it from a data table. Use a condition to gate the deletion when row state must match before removal.
Prerequisites
Install Tablestore SDK for Java and initialize the client.
Description
public DeleteRowResponse deleteRow(DeleteRowRequest deleteRowRequest) throws TableStoreException, ClientException
Delete a single row located by its primary key. Specify the primary key in RowDeleteChange. The response exposes the consumed capacity units (CUs) through response.getConsumedCapacity().
The following example deletes the row whose primary key is row1 from the data table delete_row_demo.
String tableName = "delete_row_demo";
PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
primaryKeyBuilder.addPrimaryKeyColumn("id", PrimaryKeyValue.fromString("row1"));
PrimaryKey primaryKey = primaryKeyBuilder.build();
RowDeleteChange rowDeleteChange = new RowDeleteChange(tableName, primaryKey);
DeleteRowResponse response = client.deleteRow(new DeleteRowRequest(rowDeleteChange));
System.out.println("RequestId: " + response.getRequestId());
System.out.println("Write CU: " + response.getConsumedCapacity().getCapacityUnit().getWriteCapacityUnit());
Key parameters:
tableName (Required): Name of the target data table.
primaryKey (Required): The primary key. Must include all primary key columns.
Parameters
Pass single-row deletion details in RowDeleteChange with the following parameters:
|
Name |
Type |
Description |
|
tableName (Required) |
String |
Name of the target data table. |
|
primaryKey (Required) |
PrimaryKey |
Primary key of the row, including column names and values.
|
|
condition (Optional) |
Condition |
The condition that gates the deletion. For more information, see Conditional update. |