HBase RowMutations to replace all columns of a row
Posted the same question on HBase user forum and turns out this is a bug in HBase.
The expected behaviour is that if a RowMutation has a Delete to some column-family/column/row followed by a Put to same column-family/column/row, the Put should also be honoured (but this is not the case currently).
HBase user group discussion on this: http://apache-hbase.679495.n3.nabble.com/Using-RowMutations-to-replace-all-columns-of-a-row-td4045247.html
HBase JIRA for the same: https://issues.apache.org/jira/browse/HBASE-8626 which also provides patch.
The closest one can do is set the timestamp on the Put to be higher than on the Delete:
long now = System.currentTimeMillis();
Delete delete = new Delete(row);
delete.deleteFamily(cf1, now);
Put put = new Put(row);
put.add(cf1, col1, now + 1);
RowMutations mutations = new RowMutations(row);
mutations.add(delete);
mutations.add(put);
table.mutateRow(mutations);
Sadly, it does mean that a get
to the timestamp 'now' will have nothing in that column family. Source