Updated on 2025-07-25 GMT+08:00

Deleting an HBase Cold and Hot Data Separation Table

Function Description

HBase allows you to delete a table using the deleteTable method of org.apache.hadoop.hbase.client.Admin.

Sample Code

public void dropTable() {
  LOG.info("Entering dropTable.");
  Admin admin = null;
  try {
    admin = conn.getAdmin();
    if (admin.tableExists(tableName)) {
      // Disable the table before deleting it.
      admin.disableTable(tableName);
      // Delete table.
      admin.deleteTable(tableName);//Note [1]
    }
    LOG.info("Drop table successfully.");
  } catch (IOException e) {
    LOG.error("Drop table failed " ,e);
  } finally {
    if (admin != null) {
      try {
        // Close the Admin object.
        admin.close();
      } catch (IOException e) {
        LOG.error("Close admin failed " ,e);
      }
    }
  }
  LOG.info("Exiting dropTable.");
}

Precautions

Note [1] Only after the disableTable API is called, the table can be deleted by calling the deleteTable API.

Therefore, deleteTable is often used together with disableTable, enableTable, tableExists, isTableEnabled, and isTableDisabled.

Note [1] refers to admin.deleteTable(tableName);//Note[1] in the sample code.