我想使用 put 替换行中列的内容,但它正在添加更新版本的数据。尝试添加时间戳,但仍在创建具有不同版本的新值。有什么想法可以替换同一版本的内容吗?
问问题
9059 次
2 回答
3
您确定您使用了正确的时间戳值吗?
我为你做了一个例子(在 hbase shell 中):
首先,我们创建一个名为 的表tmp1
,其中包含一个名为 的列族f1
,每个单元格可以有三个版本:
hbase(main):005:0> create 'tmp1', {NAME => 'f1', VERSIONS => 3}
0 row(s) in 1.1160 seconds
接下来,我们将一行带值v1
的数据放入表中:
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
然后,我们put
使用相同的 rowkey r1
、 column namef1:c1
和 timestamp做另一个1
,但使用不同的 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
如您所见,单元格已替换为新值v2
。
于 2013-03-14T11:35:12.773 回答
1
直接出自 HBase文档:
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);
于 2013-03-14T14:17:36.127 回答