What is the method for deleting a record in HBase?

To delete a record in HBase, you can achieve this by calling an instance of the Delete class. The steps to delete the data are as follows:

  1. Create an instance of the Delete class, with the constructor requiring the RowKey parameter to be passed in.
Delete delete = new Delete(Bytes.toBytes("rowkey"));
  1. Optionally, you can set a timestamp for the Delete instance to delete specific versions of data. By default, the delete operation will remove all versions of data.
delete.setTimestamp(timestamp);
  1. Optionally, you can specify column families and qualifiers for the Delete operation in order to delete specific columns.
delete.addColumn(Bytes.toBytes("columnFamily"), Bytes.toBytes("columnQualifier"));
  1. Optionally, you can set column families for a Delete operation to remove all columns within the column family.
delete.addFamily(Bytes.toBytes("columnFamily"));
  1. Optionally, you can set a timestamp range for the Delete instance to remove data within a specified timestamp range.
delete.setTimeRange(minTimestamp, maxTimestamp);
  1. Execute the delete operation using the delete() method of the Table instance.
Table table = connection.getTable(TableName.valueOf("table"));
table.delete(delete);

Please make sure that the HBase table exists and that a connection has been established before deleting data.

bannerAds