更新时间:2024-08-03 GMT+08:00

查询HBase二级索引列表

功能介绍

您可以使用org.apache.hadoop.hbase.hindex.client.HIndexAdmin中提供的方法来管理HIndexes。 该类提供了列出表的现有索引的方法。

HIndexAdmin为给定表格列出索引提供以下API:

  • listIndices(): 该API可用于列出给定表的所有索引。

代码样例

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

  public void listIndicesIntable() {
    LOG.info("Entering Listing Hindex.");
    Admin admin = null;
    HIndexAdmin iAdmin = null;
    try {
      admin = conn.getAdmin();
      iAdmin = HIndexClient.newHIndexAdmin(admin);
      // Retreive the list of indices and print it
      List<Pair<HIndexSpecification, IndexState>> indicesList = iAdmin.listIndices(tableName);
      LOG.info("indicesList:" + indicesList);
      LOG.info("Successfully listed indices for table " + tableName + ".");
    } catch (IOException e) {
      LOG.error("Failed to list indices for table " + tableName + "." + e);
    } finally {
      if (iAdmin != null) {
        try {
          // Close the HIndexAdmin object.
          iAdmin.close();
        } catch (IOException e) {
          LOG.error("Failed to close HIndexAdmin ", e);
        }
      }
      if (admin != null) {
        try {
          // Close the Admin object.
          admin.close();
        } catch (IOException e) {
          LOG.error("Failed to close admin ", e);
        }
      }
    }
    LOG.info("Exiting Listing Hindex.");
  }