Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete all data in a Cassandra column family?

Tags:

cassandra

I'm looking for a way to delete all of the rows from a given column family in cassandra.

This is the equivalent of TRUNCATE TABLE in SQL.

like image 642
Ike Walker Avatar asked May 09 '12 16:05

Ike Walker


People also ask

How do I delete all data from Cassandra table?

To remove all rows from a CQL Table, you can use the TRUNCATE command: TRUNCATE keyspace_name.

How do I delete an entire row in Cassandra?

Use the DELETE command to replace the value in a column with null or to remove an entire row of data. CQL provides the DELETE command to delete a column or row.

How does Cassandra delete data?

Cassandra treats a delete as an insert or upsert. The data being added to the partition in the DELETE command is a deletion marker called a tombstone. The tombstones go through Cassandra's write path, and are written to SSTables on one or more nodes.


3 Answers

You can use the truncate thrift call, or the TRUNCATE <table> command in CQL.

http://www.datastax.com/docs/1.0/references/cql/TRUNCATE

like image 200
the paul Avatar answered Sep 22 '22 21:09

the paul


You can also do this via Cassandra CQL.

$ cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.6 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh> TRUNCATE my_keyspace.my_column_family;
like image 35
cevaris Avatar answered Sep 24 '22 21:09

cevaris


Its very simple in Astyanax. Just a Single Line statement

/* keyspace variable is Keyspace Type */
keyspace.truncateColumnFamily(ColumnFamilyName); 
like image 22
abhi Avatar answered Sep 24 '22 21:09

abhi