MAPREDUCE服务 MRS-添加HBase二级索引:代码样例
代码样例
以下代码片段在com.huawei.bigdata.hbase.examples包的“HIndexExample”类的addIndicesExample方法中:
addIndices(): 将索引添加到没有数据的表中
public void addIndicesExample() { LOG .info("Entering Adding a Hindex."); // Create index instance TableIndices tableIndices = new TableIndices(); HIndexSpecification spec = new HIndexSpecification(indexNameToAdd); spec.addIndexColumn(new HColumnDescriptor("info"), "name", ValueType.STRING); tableIndices.addIndex(spec); Admin admin = null; HIndexAdmin iAdmin = null; try { admin = conn.getAdmin(); iAdmin = HIndexClient.newHIndexAdmin(admin); // add index to the table iAdmin.addIndices(tableName, tableIndices); // Alternately, add the specified indices with data // iAdmin.addIndicesWithData(tableName, tableIndices); LOG.info("Successfully added indices to the table " + tableName); } catch (IOException e) { LOG.error("Add Indices failed 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 Adding a Hindex."); }
以下代码片段在com.huawei.bigdata.hbase.examples包的“HIndexExample”类的addIndicesExampleWithData方法中:
addIndicesWithData():将索引添加到具有大量预先存在数据的表中
public void addIndicesExampleWithData() { LOG.info("Entering Adding a Hindex With Data."); // Create index instance TableIndices tableIndices = new TableIndices(); HIndexSpecification spec = new HIndexSpecification(indexNameToAdd); spec.addIndexColumn(new HColumnDescriptor("info"), "age", ValueType.STRING); tableIndices.addIndex(spec); Admin admin = null; HIndexAdmin iAdmin = null; try { admin = conn.getAdmin(); iAdmin = HIndexClient.newHIndexAdmin(admin); // add index to the table iAdmin.addIndicesWithData(tableName, tableIndices); // Alternately, add the specified indices with data // iAdmin.addIndicesWithData(tableName, tableIndices); LOG.info("Successfully added indices to the table " + tableName); } catch (IOException e) { LOG.error("Add Indices failed 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 Adding a Hindex With Data."); }
- MapReduce服务_如何使用MapReduce服务_MRS集群客户端安装与使用
- 大数据分析是什么_使用MapReduce_创建MRS服务
- MapReduce服务_什么是MapReduce服务_什么是HBase
- 什么是Spark_如何使用Spark_Spark的功能是什么
- MapReduce工作原理_MapReduce是什么意思_MapReduce流程_MRS_华为云
- Hudi服务_什么是Hudi_如何使用Hudi
- GaussDB索引_GaussDB数据库索引_高斯数据库索引_华为云
- Couchbase镜像下载
- MapReduce服务_什么是ZooKeeper_如何使用ZooKeeper
- 等保二级三级