Chris Chris - 2 months ago 19
Java Question

How to delete a column of a single row in 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 UnsupportedOperationException:

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?


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.