开发者

HBase copy one row (rename row key) in Java

开发者 https://www.devze.com 2023-03-25 15:41 出处:网络
I know in HBase, the key of the row can not be changed. But I really need a 开发者_如何学Crow key rename function.

I know in HBase, the key of the row can not be changed.

But I really need a 开发者_如何学Crow key rename function. How can I copy one row to another row in HBase using JAVA?

e.g. I have existing row with key "key1", and I want to create a row with key "key2" copied from "key1" row.

Thanks a million!


Not sure if you already figured it out. But this is pretty straightforward stuff. Just create a new Put with the new row key and copy contents from old key.

        // lets say your already got the result from table.get(Bytes.toBytes("key1"))
        Put put = new Put(Bytes.toBytes("key2"));

        NavigableMap<byte[], NavigableMap<byte[], byte[]>> familyQualifierMap = result.getNoVersionMap();
        for (byte[] familyBytes : familyQualifierMap.keySet()) {
            NavigableMap<byte[], byte[]> qualifierMap = familyQualifierMap.get(familyBytes);

            for (byte[] qualifier : qualifierMap.keySet()) {
                put.add(familyBytes, qualifier, qualifierMap.get(qualifier));
            }            
        }            
        table.put(put);
        table.flushCommits();
        table.close();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号