hbase删除基于部分id的记录 [英] hbase delete records based on portion of id
问题描述
我想知道是否可以根据行的id从表中删除记录。例如,我创建了一个名为'hbase_test'的表,其中的'cmmnttest'和列'cmmntpost'创建了如下的ID:
'99 .abcdefghijkil'
'99 .oiuerwrerwwre'
我需要查找所有具有以'99'开头的id并删除它们的行。这是一个客户端ID'99'和记录值的组合。
我发现以下但不确定它是否适用于此:
要从't1'行'r1'处的'c1'列下删除一个单元格,
用时间'ts1'标记,执行:
hbase> delete'据我所知,你不能在HBase shell中做到这一点,但是,我不知道你在做什么。 ,但您可以使用Java API轻松完成,您只需创建一个提供99的扫描仪即可。作为起始行键和100。作为停止rowkey,迭代所有结果并批量删除它们:
Configuration conf = HBaseConfiguration.create();
HTable表=新的HTable(conf,myTable);
ArrayList< Delete> deleteList = new ArrayList< Delete>();
int maxDeletesPerBatch = 1000;
扫描扫描=新扫描(99。。getBytes(),100。。getBytes()); //分隔符用于避免定位999,9999,99999...
scan.setCaching(maxDeletesPerBatch); //分批获取扫描结果
ResultScanner扫描器= table.getScanner(scan);
尝试{
for(Result result:scanner){
deleteList.add(new Delete(result.getRow()));
if(deleteList.size()== maxDeletesPerBatch){
//最大删除达到,清除删除并清除列表
table.delete(deleteList);
deleteList.clear();
}
}
} finally {
scanner.close();
if(deleteList.size()> 0){
//刷新剩余删除
table.delete(deleteList);
}
table.close();
}
I would like to know if it is possible to delete records from a table based on the id of the row. For example I created a table named 'hbase_test' with the family 'cmmnttest' and column 'cmmntpost' with the ids created as follows:
'99.abcdefghijkil'
'99.oiuerwrerwwre'
I need to find all rows that have id starting with '99' and delete them. This is a combination of a client id '99' and the value of the record.
I found the following but not sure if it applies here:
To delete a cell from ‘t1′ at row ‘r1′ under column ‘c1′ marked with the time ‘ts1′, do: hbase> delete ‘t1′, ‘r1′, ‘c1′, ts1
As far as I know you cannot do that in the HBase shell, but you can easily do it with the Java API, you'll just have to create a scanner providing "99." as start rowkey and "100." as stop rowkey, iterate all the results and delete them in batches:
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();
}
这篇关于hbase删除基于部分id的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!