當前位置: 首頁>>代碼示例>>Java>>正文


Java HTable.delete方法代碼示例

本文整理匯總了Java中org.apache.hadoop.hbase.client.HTable.delete方法的典型用法代碼示例。如果您正苦於以下問題:Java HTable.delete方法的具體用法?Java HTable.delete怎麽用?Java HTable.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.hbase.client.HTable的用法示例。


在下文中一共展示了HTable.delete方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: deleteRow

import org.apache.hadoop.hbase.client.HTable; //導入方法依賴的package包/類
public static void deleteRow(String tablename, String rowkey) {
    try {
        HTable table = new HTable(configuration, tablename);
        List list = new ArrayList();
        Delete d1 = new Delete(rowkey.getBytes());
        list.add(d1);

        table.delete(list);
        System.out.println("刪除行成功!");

    } catch (IOException e) {
        e.printStackTrace();
    }


}
 
開發者ID:yjp123456,項目名稱:SparkDemo,代碼行數:17,代碼來源:MyClass.java

示例2: deleteTableData

import org.apache.hadoop.hbase.client.HTable; //導入方法依賴的package包/類
/**
 * Provide an existing table name to truncate.
 * Scans the table and issues a delete for each row read.
 * @param tableName existing table
 * @return HTable to that new table
 * @throws IOException
 */
public HTable deleteTableData(TableName tableName) throws IOException {
  HTable table = new HTable(getConfiguration(), tableName);
  Scan scan = new Scan();
  ResultScanner resScan = table.getScanner(scan);
  for(Result res : resScan) {
    Delete del = new Delete(res.getRow());
    table.delete(del);
  }
  resScan = table.getScanner(scan);
  resScan.close();
  return table;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:20,代碼來源:HBaseTestingUtility.java

示例3: deleteNumericRows

import org.apache.hadoop.hbase.client.HTable; //導入方法依賴的package包/類
public void deleteNumericRows(final HTable t, final byte[] f, int startRow, int endRow)
    throws IOException {
  for (int i = startRow; i < endRow; i++) {
    byte[] data = Bytes.toBytes(String.valueOf(i));
    Delete delete = new Delete(data);
    delete.deleteFamily(f);
    t.delete(delete);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:10,代碼來源:HBaseTestingUtility.java

示例4: testHbckWithExcessReplica

import org.apache.hadoop.hbase.client.HTable; //導入方法依賴的package包/類
@Test
public void testHbckWithExcessReplica() throws Exception {
  TableName table =
      TableName.valueOf("testHbckWithExcessReplica");
  try {
    setupTableWithRegionReplica(table, 2);
    TEST_UTIL.getHBaseAdmin().flush(table.getName());
    assertNoErrors(doFsck(conf, false));
    assertEquals(ROWKEYS.length, countRows());
    // the next few lines inject a location in meta for a replica, and then
    // asks the master to assign the replica (the meta needs to be injected
    // for the master to treat the request for assignment as valid; the master
    // checks the region is valid either from its memory or meta)
    HTable meta = new HTable(conf, TableName.META_TABLE_NAME);
    List<HRegionInfo> regions = TEST_UTIL.getHBaseAdmin().getTableRegions(table);
    byte[] startKey = Bytes.toBytes("B");
    byte[] endKey = Bytes.toBytes("C");
    byte[] metaKey = null;
    HRegionInfo newHri = null;
    for (HRegionInfo h : regions) {
      if (Bytes.compareTo(h.getStartKey(), startKey) == 0  &&
          Bytes.compareTo(h.getEndKey(), endKey) == 0 &&
          h.getReplicaId() == HRegionInfo.DEFAULT_REPLICA_ID) {
        metaKey = h.getRegionName();
        //create a hri with replicaId as 2 (since we already have replicas with replicaid 0 and 1)
        newHri = RegionReplicaUtil.getRegionInfoForReplica(h, 2);
        break;
      }
    }
    Put put = new Put(metaKey);
    ServerName sn = TEST_UTIL.getHBaseAdmin().getClusterStatus().getServers()
        .toArray(new ServerName[0])[0];
    //add a location with replicaId as 2 (since we already have replicas with replicaid 0 and 1)
    MetaTableAccessor.addLocation(put, sn, sn.getStartcode(), -1, 2);
    meta.put(put);
    meta.flushCommits();
    // assign the new replica
    HBaseFsckRepair.fixUnassigned((HBaseAdmin)TEST_UTIL.getHBaseAdmin(), newHri);
    HBaseFsckRepair.waitUntilAssigned((HBaseAdmin)TEST_UTIL.getHBaseAdmin(), newHri);
    // now reset the meta row to its original value
    Delete delete = new Delete(metaKey);
    delete.deleteColumns(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerColumn(2));
    delete.deleteColumns(HConstants.CATALOG_FAMILY, MetaTableAccessor.getStartCodeColumn(2));
    delete.deleteColumns(HConstants.CATALOG_FAMILY, MetaTableAccessor.getSeqNumColumn(2));
    meta.delete(delete);
    meta.flushCommits();
    meta.close();
    // check that problem exists
    HBaseFsck hbck = doFsck(conf, false);
    assertErrors(hbck, new ERROR_CODE[]{ERROR_CODE.NOT_IN_META});
    // fix the problem
    hbck = doFsck(conf, true);
    // run hbck again to make sure we don't see any errors
    hbck = doFsck(conf, false);
    assertErrors(hbck, new ERROR_CODE[]{});
  } finally {
    cleanupTable(table);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:60,代碼來源:TestHBaseFsck.java


注:本文中的org.apache.hadoop.hbase.client.HTable.delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。