Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hbase put to replace existing column value

Tags:

hadoop

hbase

I want to replace content of a column in a row using put but it is adding newer version of data. Tried adding time stamp but still a new value with different version is getting created. Any ideas to replace content on same version ?

like image 565
tousif Avatar asked Jul 02 '26 02:07

tousif


2 Answers

Are you sure you have used the right timestamp value?

I have made an example for you(in hbase shell):

At first, we create a table named tmp1 with one column family named f1, which can has three versions for each cell:

hbase(main):005:0> create 'tmp1', {NAME => 'f1', VERSIONS => 3}
0 row(s) in 1.1160 seconds

Next, we put one row with value v1 into the table:

hbase(main):007:0> put 'tmp1', 'r1', 'f1:c1', 'v1', 1
0 row(s) in 0.0860 seconds
hbase(main):008:0> scan 'tmp1'
    ROW                                            COLUMN+CELL
    r1                                            column=f1:c1, timestamp=1, value=v1
1 row(s) in 0.0390 seconds

Then, we do another put with the same rowkey r1, column name f1:c1 and timestamp 1, but with a different value v2:

hbase(main):009:0> put 'tmp1', 'r1', 'f1:c1', 'v2', 1
0 row(s) in 0.0060 seconds

hbase(main):008:0> scan 'tmp1'
    ROW                                            COLUMN+CELL
    r1                                            column=f1:c1, timestamp=1, value=v2

As you can see, the cell has been replaced with the new value v2.

like image 51
ericson Avatar answered Jul 04 '26 20:07

ericson


Straight out of the HBase documentation:

Put put = new Put( Bytes.toBytes(row)); 
long explicitTimeInMs = 555; // just an example
put.add(Bytes.toBytes("cf"), Bytes.toBytes("attr1"), explicitTimeInMs, Bytes.toBytes(data));
htable.put(put);
like image 26
Pieterjan Avatar answered Jul 04 '26 21:07

Pieterjan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!