我想知道是否可以根据行的id从表中删除记录。例如,我创建了一个名为'hbase_test'的表,其系列为'cmmnttest',列为'cmmntpost',其中id为如下所示:
'99.abcdefghijkil'
'99.oiuerwrerwwre'
我需要查找id为'99'的所有行并删除它们。这是客户端ID“99”和记录值的组合。
我发现以下内容但不确定它是否适用于此:
从“c1”列下的“r1”行删除“t1”中的单元格 标有时间'ts1',执行: HBase的>删除't1','r1','c1',ts1
答案 0 :(得分:2)
据我所知,你不能在HBase shell中做到这一点,但你可以使用Java API轻松完成,你只需要创建一个提供“99”的扫描程序。作为start rowkey和“100”。作为stop rowkey,迭代所有结果并批量删除它们:
Configuration conf = HBaseConfiguration.create();
HTable table = new HTable(conf, "myTable");
ArrayList<Delete> deleteList = new ArrayList<Delete>();
int maxDeletesPerBatch = 1000;
Scan scan = new Scan( "99.".getBytes(), "100.".getBytes()); // Separator used to avoid targeting "999", "9999", "99999" ...
scan.setCaching(maxDeletesPerBatch); // Get the scanner results in batches
ResultScanner scanner = table.getScanner(scan);
try {
for (Result result : scanner) {
deleteList.add(new Delete(result.getRow()));
if (deleteList.size() == maxDeletesPerBatch) {
// Max deletes reached, flush deletes and clear the list
table.delete(deleteList);
deleteList.clear();
}
}
} finally {
scanner.close();
if (deleteList.size() > 0) {
// Flush remaining deletes
table.delete(deleteList);
}
table.close();
}