Updated on 2022-11-18 GMT+08:00

Deleting an Index

Function

You can manage HBase secondary indexes using methods provided in org.apache.hadoop.hbase.hindex.client.HIndexAdmin. This class provides methods of querying and deleting an index.

Example Code

The following code snippet belongs to the dropIndex method in the HBaseSample class of the com.huawei.bigdata.hbase.examples package.

public void dropIndex() {
    LOG.info("Entering dropIndex.");
    String indexName = "index_name";
    List<String> indexNameList = new ArrayList<String>();
    indexNameList.add(indexName);

    IndexAdmin iAdmin = null;
    try {
      // Instantiate HIndexAdmin Object
      iAdmin = HIndexClient.newHIndexAdmin(conn.getAdmin());
      // Delete Secondary Index
      iAdmin.dropIndex(tableName, indexNameList);

      LOG.info("Drop index successfully.");
    } catch (IOException e) {
      LOG.error("Drop index failed.");
    } finally {
      if (iAdmin != null) {
        try {
          // Close Secondary Index
          iAdmin.close();
        } catch (IOException e) {
          LOG.error("Close admin failed.");
        }
      }
    }
    LOG.info("Exiting dropIndex.");
  }