Chris Chris - 1 year ago 93
Java Question

How to delete a column of a single row in Google Cloud Bigtable with HBase API

I'm using the HBase API to access Google Cloud Bigtable, but whenever I try to delete a column:

Delete delete = new Delete(r.getRow());
delete.addColumn(CF, Bytes.toBytes(d.seqid()));
delete.addColumn(CF, COL_LEASE);

I'm getting an

java.lang.UnsupportedOperationException: Cannot delete single latest cell.
at queue.BigTableRowBackedQueue.poll(

I saw in the code it occurs here.

I can delete the entire row fine from the HBase Java client, and I can delete individual columns fine by using the HBase shell.

How can I delete columns without removing the row in the Java client?

Answer Source

Sorry for your troubles. Bigtable and HBase differ in a couple of ways, and this is one of them.

Delete delete = new Delete(rowKey);
delete.addColumns(COLUMN_FAMILY, qual); // the 's' matters

HBase's Delete.addColumn deletes only the latest cell from the column. The Delete.addColumn_s_ means delete all cells (i.e. all the various timestamps). Alternatively, you can delete a specific cell via Delete.addColumn(byte[], byte[], long) where the long is a timestamp.

The hbase shell delete uses deleteColumns which maps to addColumns under the cover. It also uses the s variation, which is why it works.

For reference here is our complete TestDelete suite which identify the use case you present as @Category(KnownGap.class) which we use to identify differences missing HBase features in the Bigtable client.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download