bigtablegoogle-cloud-bigtablecbt

How to use cbt to delete range of rows with a prefix key from BigTable?


Looks like I can read rows with a prefixed key using cbt like so:

cbt -project someproject -instance someinstance read sometable prefix=abc

But how can I use the cbt command to delete those rows as selected by the above command?


Solution

  • To be able to do this using only cbt, you would to parse the output of the read command and iterate through each result executing the deleterow command for the specific rows.

    Alternatively, you could use one of the Bigtable’s Client Libraries which would be much faster.

    Like in the Java client, you will find this same functionality in the other clients as well, like in the DropRowRangeRequest class for the C# Client Library.

    EDIT: To delete a few rows using only cbt you could use something like this:

    for x in `cbt -project my-project -instance my-instance read my-table prefix=abc | grep "abc"`; do 
      cbt -project my-project -instance my-instance deleterow my-table $x;
    done