Mahebub A Sayyed
Mahebub A Sayyed

Reputation: 364

How to update existing column value in HBase

I have following insert statement.

Put put = new Put(UserId.getBytes(charSet));
put.add("Actor".getBytes(charSet), "Verified".getBytes(charSet),Bytes.toBytes(verified));       
put.add("Actor".getBytes(charSet), "UtcOffset".getBytes(charSet),Bytes.toBytes(utcOffset));
put.add("Actor".getBytes(charSet), "PreferredUsername".getBytes(charSet),preferredUserName.getBytes(charSet));  
table.put(put);

Now I want to update inserted value preferredUserName with new preferredUsername. Please help me

Upvotes: 1

Views: 5960

Answers (1)

Shawn H
Shawn H

Reputation: 103

In HBase, you can update values in different column-qualifiers separately, and the old value in one column-qualifer will be "shadowed" by the new value. Strictly speaking, the new value forms a new version, and by default you always Get the latest version if you don't specify timestamps in Get/Scan.

So just "Put" the new preferredUsername into "PreferredUsername" column-qualifier.

Put put = new Put(UserId.getBytes(charSet));
put.add("Actor".getBytes(charSet), "PreferredUsername".getBytes(charSet),newPreferredUserName.getBytes(charSet));  
table.put(put);

This will "shadow" inserted preferredUserName with newPreferredUserName for the "UserId" row.

Upvotes: 6

Related Questions