删除HBase二级索引
功能简介
一般都通过调用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.");
}