This topic describes how to use Tablestore SDK for Java to delete a single row of data from a Tablestore table.
Prerequisites
A client is initialized. For more information, see Initialize a Tablestore client.
Method
public DeleteRowResponse deleteRow(DeleteRowRequest deleteRowRequest) throws TableStoreException, ClientExceptionSample code
The following sample code deletes a row with the primary key value of row1 from the test_table table.
public static void deleteRowExample(SyncClient client) {
// Construct the primary key.
PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
primaryKeyBuilder.addPrimaryKeyColumn("id", PrimaryKeyValue.fromString("row1"));
PrimaryKey primaryKey = primaryKeyBuilder.build();
// Construct the row data to be deleted.
RowDeleteChange rowDeleteChange = new RowDeleteChange("test_table", primaryKey);
// Call the deleteRow method to delete the row data.
DeleteRowRequest deleteRowRequest = new DeleteRowRequest(rowDeleteChange);
DeleteRowResponse deleteRowResponse = client.deleteRow(deleteRowRequest);
// Return the result.
System.out.println("RequestId: " + deleteRowResponse.getRequestId());
System.out.println("Read CU Cost: " + deleteRowResponse.getConsumedCapacity().getCapacityUnit().getReadCapacityUnit());
System.out.println("Write CU Cost: " + deleteRowResponse.getConsumedCapacity().getCapacityUnit().getWriteCapacityUnit());
}