Java Code Examples for org.apache.hadoop.hbase.client.HTableInterface#delete()

The following examples show how to use org.apache.hadoop.hbase.client.HTableInterface#delete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AclService.java    From Kylin with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException {
    HTableInterface htable = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName);
        Delete delete = new Delete(Bytes.toBytes(String.valueOf(objectIdentity.getIdentifier())));

        List<ObjectIdentity> children = findChildren(objectIdentity);
        if (!deleteChildren && children.size() > 0) {
            throw new ChildrenExistException("Children exists for " + objectIdentity);
        }

        for (ObjectIdentity oid : children) {
            deleteAcl(oid, deleteChildren);
        }

        htable.delete(delete);
        htable.flushCommits();

        logger.debug("ACL of " + objectIdentity + " deleted successfully.");
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(htable);
    }
}
 
Example 2
Source File: HBaseAction.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public Status act(UpstreamJob job, byte[] bytes) {
    HBaseConnection connection = connectionMap.get(job.getTopic());
    if (connection == null) {
        LogUtils.logErrorInfo("HBASE_error", "no hbase connection for topic=" + job.getTopic());
        return FAIL;
    }

    if (CollectionUtils.isNotEmpty(job.getHbaseCommands())) {
        try {
            for (HbaseCommand hbaseCommand : job.getHbaseCommands()) {
                HTableInterface table = connection.getTable(hbaseCommand.getTableName());
                Mutation mutation = hbaseCommand.getMutation();

                if (mutation instanceof Put) {
                    table.put((Put) mutation);
                } else if (mutation instanceof Delete) {
                    table.delete((Delete) mutation);
                } else if (mutation instanceof Append) {
                    table.append((Append) mutation);
                } else if (mutation instanceof Increment) {
                    table.increment((Increment) mutation);
                }
            }
            MetricUtils.qpsAndFilterMetric(job, MetricUtils.ConsumeResult.SUCCESS);
            return FINISH;
        } catch (IOException e) {
            LogUtils.logErrorInfo("HBASE_error", "job=" + job, e);
            return FAIL;
        }
    } else {
        LogUtils.logErrorInfo("HBASE_error", "no hbase command found, group:{}, topic:{}", group, job.getTopic());
        return FAIL;
    }
}
 
Example 3
Source File: IndexedRegion.java    From hbase-secondary-index with GNU General Public License v3.0 5 votes vote down vote up
private void updateIndex(final IndexSpecification indexSpec, final Put put,
    final NavigableMap<byte[], byte[]> newColumnValues,
    final SortedMap<byte[], byte[]> oldColumnValues) throws IOException {
  Delete indexDelete = makeDeleteToRemoveOldIndexEntry(indexSpec,
      put.getRow(), oldColumnValues);
  Put indexPut = makeIndexUpdate(indexSpec, put.getRow(), newColumnValues);

  HTableInterface indexTable = getIndexTable(indexSpec);
  try {
    if (indexDelete != null
        && !Bytes.equals(indexDelete.getRow(), indexPut.getRow())) {
      // Only do the delete if the row changed. This way we save the put after
      // delete issues in HBASE-2256
      LOG.debug("Deleting old index row ["
          + Bytes.toString(indexDelete.getRow()) + "]. New row is ["
          + Bytes.toString(indexPut.getRow()) + "].");
      indexTable.delete(indexDelete);
    } else if (indexDelete != null) {
      LOG.debug("Skipping deleting index row ["
          + Bytes.toString(indexDelete.getRow())
          + "] because it has not changed.");
    }
    indexTable.put(indexPut);
  } finally {
    putTable(indexTable);
  }
}
 
Example 4
Source File: HBaseBackedTransactionLogger.java    From hbase-secondary-index with GNU General Public License v3.0 5 votes vote down vote up
public void forgetTransaction(final long transactionId) {
    Delete delete = new Delete(getRow(transactionId));

    HTableInterface table = getTable();
    try {
        table.delete(delete);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        putTable(table);
    }
}
 
Example 5
Source File: AbstractHBaseClient.java    From jstorm with Apache License 2.0 5 votes vote down vote up
protected void deleteRow(String tableName, byte[] key) {
    HTableInterface table = getHTableInterface(tableName);
    Delete delete = new Delete(key);

    HTableInterface htable;
    try {
        htable = getHTableInterface(tableName);
        htable.delete(delete);
    } catch (Exception ex) {
        logger.error("Failed to delete row, table:{}, key:{}", tableName, key, ex);
    } finally {
        closeTable(table);
    }
}
 
Example 6
Source File: HBaseResourceStore.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected void deleteResourceImpl(String resPath) throws IOException {
    HTableInterface table = getConnection().getTable(getAllInOneTableName());
    try {
        Delete del = new Delete(Bytes.toBytes(resPath));
        table.delete(del);
        table.flushCommits();
    } finally {
        IOUtils.closeQuietly(table);
    }
}
 
Example 7
Source File: UserService.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteUser(String username) {
    HTableInterface htable = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(userTableName);
        Delete delete = new Delete(Bytes.toBytes(username));

        htable.delete(delete);
        htable.flushCommits();
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(htable);
    }
}
 
Example 8
Source File: DataJanitorState.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void deleteFromScan(HTableInterface stateTable, Scan scan) throws IOException {
  try (ResultScanner scanner = stateTable.getScanner(scan)) {
    Result next;
    while ((next = scanner.next()) != null) {
      stateTable.delete(new Delete(next.getRow()));
    }
  }
}
 
Example 9
Source File: DataJanitorState.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void deleteFromScan(HTableInterface stateTable, Scan scan) throws IOException {
  try (ResultScanner scanner = stateTable.getScanner(scan)) {
    Result next;
    while ((next = scanner.next()) != null) {
      stateTable.delete(new Delete(next.getRow()));
    }
  }
}
 
Example 10
Source File: HBaseAction.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public Status act(UpstreamJob job, byte[] bytes) {
    HBaseConnection connection = connectionMap.get(job.getTopic());
    if (connection == null) {
        LogUtils.logErrorInfo("HBASE_error", "no hbase connection for topic=" + job.getTopic());
        return FAIL;
    }

    if (CollectionUtils.isNotEmpty(job.getHbaseCommands())) {
        try {
            for (HbaseCommand hbaseCommand : job.getHbaseCommands()) {
                HTableInterface table = connection.getTable(hbaseCommand.getTableName());
                Mutation mutation = hbaseCommand.getMutation();

                if (mutation instanceof Put) {
                    table.put((Put) mutation);
                } else if (mutation instanceof Delete) {
                    table.delete((Delete) mutation);
                } else if (mutation instanceof Append) {
                    table.append((Append) mutation);
                } else if (mutation instanceof Increment) {
                    table.increment((Increment) mutation);
                }
            }
            MetricUtils.qpsAndFilterMetric(job, MetricUtils.ConsumeResult.SUCCESS);
            return FINISH;
        } catch (IOException e) {
            LogUtils.logErrorInfo("HBASE_error", "job=" + job, e);
            return FAIL;
        }
    } else {
        LogUtils.logErrorInfo("HBASE_error", "no hbase command found, group:{}, topic:{}", group, job.getTopic());
        return FAIL;
    }
}
 
Example 11
Source File: HBaseDMLHandler.java    From bigdata-tutorial with Apache License 2.0 3 votes vote down vote up
/**
 * delete a row identified by rowkey
 *
 * @param tableName
 * @param rowKey
 * @throws Exception
 */
public void deleteFamily(String tableName, String rowKey, String family) throws Exception {
	HTableInterface htable = getTable(tableName);
	Delete delete = new Delete(Bytes.toBytes(rowKey));
	delete.deleteFamily(Bytes.toBytes(family));
	htable.delete(delete);
}
 
Example 12
Source File: HBaseDMLHandler.java    From bigdata-tutorial with Apache License 2.0 3 votes vote down vote up
/**
 * delete a row identified by rowkey
 *
 * @param tableName
 * @param rowKey
 * @throws Exception
 */
public void deleteQualifier(String tableName, String rowKey, String family, String qualifier) throws Exception {
	HTableInterface htable = getTable(tableName);
	Delete delete = new Delete(Bytes.toBytes(rowKey));
	delete.deleteColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));
	htable.delete(delete);
}
 
Example 13
Source File: HBaseUtils.java    From bigdata-tutorial with Apache License 2.0 3 votes vote down vote up
/**
 * delete a row family:qualifier data by rowkey
 *
 * @param table
 * @param rowKey
 * @throws Exception
 */
public static void deleteQualifier(HTableInterface table, String rowKey, String family, String qualifier) throws Exception {
	Delete delete = new Delete(Bytes.toBytes(rowKey));
	delete.deleteColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));
	table.delete(delete);
	LOGGER.info(">>>> HBase Delete {} data with key = {}, columnFamily = {}, qualifier = {}.", new String(table.getTableName()), rowKey, family, qualifier);
}
 
Example 14
Source File: HBaseUtils.java    From bigdata-tutorial with Apache License 2.0 3 votes vote down vote up
/**
 * delete a row column family by rowkey
 *
 * @param table
 * @param rowKey
 * @throws Exception
 */
public static void deleteFamily(HTableInterface table, String rowKey, String family) throws Exception {
	Delete delete = new Delete(Bytes.toBytes(rowKey));
	delete.deleteFamily(Bytes.toBytes(family));
	table.delete(delete);
	LOGGER.info(">>>> HBase Delete {} data with key = {}, columnFamily = {}.", new String(table.getTableName()), rowKey, family);
}
 
Example 15
Source File: HBaseDMLHandler.java    From bigdata-tutorial with Apache License 2.0 2 votes vote down vote up
/**
 * delete a row identified by rowkey
 *
 * @param tableName
 * @param rowKey
 * @throws Exception
 */
public void deleteRow(String tableName, String rowKey) throws Exception {
	HTableInterface htable = getTable(tableName);
	Delete delete = new Delete(Bytes.toBytes(rowKey));
	htable.delete(delete);
}
 
Example 16
Source File: HBaseFactoryTest.java    From bigdata-tutorial with Apache License 2.0 2 votes vote down vote up
/**
 * delete a row identified by rowkey
 *
 * @param table
 * @param rowKey
 * @throws Exception
 */
public static void deleteRow(HTableInterface table, String rowKey) throws Exception {
	Delete delete = new Delete(Bytes.toBytes(rowKey));
	table.delete(delete);
	LOGGER.info(">>>> Delete row: " + rowKey);
}
 
Example 17
Source File: HBaseUtils.java    From bigdata-tutorial with Apache License 2.0 2 votes vote down vote up
/**
 * delete a row by rowkey
 *
 * @param table
 * @param rowKey
 * @throws Exception
 */
public static void deleteRow(HTableInterface table, String rowKey) throws Exception {
	Delete delete = new Delete(Bytes.toBytes(rowKey));
	table.delete(delete);
	LOGGER.info(">>>> HBase Delete {} row with key = {} ", new String(table.getTableName()), rowKey);
}