Jake Pearson
Jake Pearson

Reputation: 27717

Delete all rows with certain keys in Cassandra

Assume I have a ColumnFamily in Cassandra that looks like:

KEY   | VALUE
_____________
foo_a | data
foo_b | data
bar_a | data
bar_b | data

What would be the best way to delete all the rows where the key starts with "foo"? I can change the structure of the data if that is useful.

Upvotes: 1

Views: 394

Answers (1)

nickmbailey
nickmbailey

Reputation: 3684

The only way to do that would be to scan every row in the cluster and programmatically check if it starts with 'foo' and delete it if so.

If you need functionality like that you could potentially keep an index of rows that start with 'foo'. Every time you write a row that starts with 'foo' you would also write the full key of that row to an index row. Then you can easily do a lookup to find all keys that start with 'foo' when you want to delete them. With that strategy you will want to make sure your index row doesn't grow too large. There is a technical limit of 2 billion columns in a single row in cassandra, but you will want to stay quite smaller than 2 billion.

Upvotes: 3

Related Questions