更新时间:2023-06-20 GMT+08:00
分享

删除索引

功能简介

一般都通过调用org.apache.hadoop.hbase.hindex.client.HIndexAdmin中方法进行HBase二级索引的管理,该类中提供了索引的查询和删除等方法。

代码样例

以下代码片段在com.huawei.bigdata.hbase.examples包的“HBaseSample”类的dropIndex方法中。

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.");
  } 
分享:

    相关文档

    相关产品