hbase删除一行中的一列,如何根据Hbase中的rowkey删除所有列的最新版本

I've a requirement with deleting the data from Hbase. I want to delete the latest version of each cell based on the row key in Hbase.

I thought of an approach to get the column names and latest timestamp of each column with the given rowkey.....then perform the delete operation iteratively with each column and its time stamp.

But I'm not able to get the column names, so I'm not able do it.

Please share if you have any thoughts or working code ?

解决方案Deletes work by creating tombstone markers. For example, let's suppose

we want to delete a row. For this you can specify a version, or else

by default the currentTimeMillis is used. What this means is “delete

all cells where the version is less than or equal to this version”.

HBase never modifies data in place, so for example a delete will not

immediately delete (or mark as deleted) the entries in the storage

file that correspond to the delete condition. Rather, a so-called

tombstone is written, which will mask the deleted values[17]. If the

version you specified when deleting a row is larger than the version

of any value in the row, then you can consider the complete row to be

deleted.

So I don't see the problem with following the standard Delete procedure.

However, if you want to delete only the latest versions of your cells you could use the setTimestamp method of Scan class. So, what you could do is:

List deletes = new ArrayList<>();

Scan scan = new Scan();

scan.setTimestamp(latestVersionTimeStamp); //latestVersionTimeStamp is a long variable

//set your filters here

ResultScanner rscanner = table.getScanner(scan);

for(Result rs : rscanner){

deletes.add(new Delete(rs.getRow()));

}

try{

table.delete(deletes);

}

catch(Exception e){

e.printStackTrace();

}

However, if your Time Stamp isn't the same across cells, this will not work for all of them. This probably will.

List deletes = new ArrayList<>();

ArrayList timestamps = new ArrayList<>();//your list of timestamps

Delete d;

Scan scan = new Scan();

//set your filters here

ResultScanner rscanner = table.getScanner(scan);

for(Pair item : zip(rscanner, timestamps)){

d=new Delete(item.getLeft().getRow())

d.setTimestamp(item.getRight());

deletes.add(d);

}

try{

table.delete(deletes);

}

catch(Exception e){

e.printStackTrace();

}

I don't guarantee this will work, however. The official guides are vague enough and I might have misinterpreted anything. If I did indeed misinterpret, alert me and I will delete this answer.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值