鲲鹏社区首页
中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

修改索引状态

alterGlobalIndicesActive API、alterGlobalIndicesInactive API和alterGlobalIndicesUnusable API用于修改索引状态,调用代表不同状态的接口将索引设置为相应状态。

alterGlobalIndicesActive API

  • alterGlobalIndicesActive API
    void alterGlobalIndicesActive(TableName tableName, List<String> indexNames)
  • 功能描述

    客户端修改索引状态请求接口,调用接口修改索引表状态为Active。

  • API描述
    1. 包名:package com.huawei.boostkit.hindex
    2. 类名:GlobalIndexAdmin
    3. 方法名:alterGlobalIndicesActive
    4. 参数详情:

      参数名称

      取值类型

      描述

      tableName

      TableName

      用户数据表

      List<String> indexNames

      List<String>

      将要修改状态的索引表

  • 使用样例
    //创建用户表myuser,并添加数据
    Admin admin = connection.getAdmin();
    TableName myuser = TableName.valueOf("myuser");
    HTableDescriptor hTableDescriptor = new HTableDescriptor(myuser);
    HColumnDescriptor f1 = new HColumnDescriptor("f1");
    hTableDescriptor.addFamily(f1);
    admin.createTable(hTableDescriptor);
    try (Table table = conn.getTable(myuser)) {
        Put put0 = new Put(Bytes.toBytes("001"));
        put0.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("test"));
        table.put(ImmutableList.of(put0));
    }
    
    //创建索引表myindex
    TableIndices myindex = new TableIndices();
    HIndexSpecification spec = new HIndexSpecification("myindex");
    //对数据表f1列族的q1创建索引,数据类型是STRING
    spec.addIndexColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), ValueType.STRING);
    myindex.addIndex(spec);
    GlobalIndexAdmin globalIndexAdmin = GlobalIndexClient.newIndexAdmin(admin);
    globalIndexAdmin.addIndicesWithData(myuser, myindex);
    
    // 修改索引表myindex状态
    globalIndexAdmin.alterGlobalIndicesUnusable(myuser, Collections.singletonList("myindex"));
    globalIndexAdmin.alterGlobalIndicesActive(myuser, Collections.singletonList("myindex"));
  • 样例结果

    myindex索引表状态成功从Active变为Unusable又变为Active。

alterGlobalIndicesInactive API

  • API
    void alterGlobalIndicesInactive(TableName tableName, List<String> indexNames)
  • 功能描述

    客户端修改索引状态请求接口,调用接口修改索引表状态为Inactive。

  • API描述
    1. 包名:package com.huawei.boostkit.hindex
    2. 类名:GlobalIndexAdmin
    3. 方法名:alterGlobalIndicesInactive
    4. 参数详情:

      参数名称

      取值类型

      描述

      tableName

      TableName

      用户数据表

      List<String> indexNames

      List<String>

      将要修改状态的索引表

  • 使用样例
    //创建用户表myuser,并添加数据
    Admin admin = connection.getAdmin();
    TableName myuser = TableName.valueOf("myuser");
    HTableDescriptor hTableDescriptor = new HTableDescriptor(myuser);
    HColumnDescriptor f1 = new HColumnDescriptor("f1");
    hTableDescriptor.addFamily(f1);
    admin.createTable(hTableDescriptor);
    try (Table table = conn.getTable(myuser)) {
        Put put0 = new Put(Bytes.toBytes("001"));
        put0.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("test"));
        table.put(ImmutableList.of(put0));
    }
    
    //创建索引表myindex
    TableIndices myindex = new TableIndices();
    HIndexSpecification spec = new HIndexSpecification("myindex");
    //对数据表f1列族的q1创建索引,数据类型是STRING
    spec.addIndexColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), ValueType.STRING);
    myindex.addIndex(spec);
    GlobalIndexAdmin globalIndexAdmin = GlobalIndexClient.newIndexAdmin(admin);
    globalIndexAdmin.addIndicesWithData(myuser, myindex);
    
    // 修改索引表myindex状态
    globalIndexAdmin.alterGlobalIndicesInactive(myuser, Collections.singletonList("myindex"));
  • 样例结果

    myindex索引表状态成功从Active变为Inactive。

alterGlobalIndicesUnusable API

  • API
    void alterGlobalIndicesUnusable(TableName tableName, List<String> indexNames)
  • 功能描述

    客户端修改索引状态请求接口,调用接口修改索引表状态为Unusable。

  • API描述
    1. 包名:package com.huawei.boostkit.hindex
    2. 类名:GlobalIndexAdmin
    3. 方法名:alterGlobalIndicesUnusable
    4. 参数详情:

      参数名称

      取值类型

      描述

      tableName

      TableName

      用户数据表

      List<String> indexNames

      List<String>

      将要修改状态的索引表

  • 使用样例
    //创建用户表myuser,并添加数据
    Admin admin = connection.getAdmin();
    TableName myuser = TableName.valueOf("myuser");
    HTableDescriptor hTableDescriptor = new HTableDescriptor(myuser);
    HColumnDescriptor f1 = new HColumnDescriptor("f1");
    hTableDescriptor.addFamily(f1);
    admin.createTable(hTableDescriptor);
    try (Table table = conn.getTable(myuser)) {
        Put put0 = new Put(Bytes.toBytes("001"));
        put0.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("test"));
        table.put(ImmutableList.of(put0));
    }
    
    //创建索引表myindex
    TableIndices myindex = new TableIndices();
    HIndexSpecification spec = new HIndexSpecification("myindex");
    //对数据表f1列族的q1创建索引,数据类型是STRING
    spec.addIndexColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), ValueType.STRING);
    myindex.addIndex(spec);
    GlobalIndexAdmin globalIndexAdmin = GlobalIndexClient.newIndexAdmin(admin);
    globalIndexAdmin.addIndicesWithData(myuser, myindex);
    
    // 修改索引表myindex状态
    globalIndexAdmin.alterGlobalIndicesUnusable(myuser, Collections.singletonList("myindex"));
  • 样例结果

    myindex索引表状态成功从Active变为Unusable。