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.");
} Precautions
- Use the dropIndex and dropIndexes interfaces to delete HBase level-2 indexes. Do not directly drop the index table, because it is an invalid operation and cannot update table information, leading to query failures at the time of index rebuilding.
- If a user table is deleted, the corresponding index table is also deleted.
Last Article: Creating a Secondary Index
Next Article: Secondary Index-based Query
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.