MAPREDUCE服务 MRS-删除HBase表数据:代码样例

时间:2024-06-29 14:11:00

代码样例

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

public void testDelete() {
     LOG .info("Entering testDelete.");

    byte[] rowKey = Bytes.toBytes("012005000201");

    Table table = null;
    try {
      // Instantiate an HTable object.
      table = conn.getTable(tableName);

      // Instantiate an Delete object.
      Delete delete = new Delete(rowKey);

      // Submit a delete request.
      table.delete(delete);

      LOG.info("Delete table successfully.");
    } catch (IOException e) {
      LOG.error("Delete table failed " ,e);
    } finally {
      if (table != null) {
        try {
          // Close the HTable object.
          table.close();
        } catch (IOException e) {
          LOG.error("Close table failed " ,e);
        }
      }
    }
    LOG.info("Exiting testDelete.");
  }     

如果被删除的cell所在的列族上设置了二级索引,也会同步删除索引数据。

support.huaweicloud.com/devg3-mrs/mrs_07_290019.html