gpt4 book ai didi

java - hbase根据id的部分删除记录

转载 作者:行者123 更新时间:2023-11-30 03:36:08 25 4
gpt4 key购买 nike

我想知道是否可以根据行的 id 从表中删除记录。例如,我创建了一个名为“hbase_test”的表,其中包含族“cmmnttest”和列“cmmntpost”,其 ID 创建如下:

'99.abcdefghijkil'
'99.oiuerwrerwwre'

我需要找到 id 以“99”开头的所有行并将其删除。这是客户端 ID“99”和记录值的组合。

我发现了以下内容,但不确定它是否适用于此:

删除“t1”中“c1”列下“r1”行的单元格标有时间“ts1”,执行:hbase>删除't1','r1','c1',ts1

最佳答案

据我所知,您无法在 HBase shell 中执行此操作,但您可以使用 Java API 轻松执行此操作,只需创建一个提供“99”的扫描器即可。作为起始行键和“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();
}

关于java - hbase根据id的部分删除记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27843407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com