You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Zhenyu Zhong <zh...@gmail.com> on 2010/01/21 20:36:21 UTC
about Delete and Put in TableOutputFormat
I tried to use Put to update a record for the same rowkey and the same
version. However, I found that it resulted in multiple values in the same
version.
For example: I can use hbase shell to fetch the values in the same
timestamp(version)
row ts value
row_a 20100101 10
row_a 20100101 11
row_a 20100101 12
Now I tried to override the TableOutputFormat class such that in the
function, basically I want to do a delete before put.
public void write(KEY key, Writable value)
throws IOException {
if (value instanceof Put) {
Put put = new Put((Put)value);
// I tried to add the delete before put
byte[] row = put.getRow();
long ts = put.getTimeStamp();
Delete delete = new Delete(row, ts, null);
// add end
this.table.delete(delete);
this.table.put(new Put((Put)value));
}
else if (value instanceof Delete) this.table.delete(new
Delete((Delete)value));
else throw new IOException("Pass a Delete or a Put");
}
However, after I rerun the data upload, I found that I couldn't use the
rowkey to fetch the record, but the strange thing is I can scan the table to
see all the rows.
May I ask what is a good way to do a delete before put for the same row key
and same timestamp?
thanks
zhenyu