Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra - how to retrieve all keys in a CF (Random Partitioner)

I am using Random Partitioner (cassandra version 0.7.8), i want to retrieve all keys in a CF. I try to use get_range_slices to do this, and it looks like i can get the keys with this method, although the keys are not ordered.

And there is also a post saying: "This is allowed with any partitioner in 0.6" (Fetching all keys using the Cassandra API -- analogy to "SELECT id FROM table;"), but the api document says it is impossible (http://wiki.apache.org/cassandra/API#get_range_slices).

My question is, is this correct to use get_range_slices in Random Partitioner? Are there any official document confirm this?

like image 304
Andy Wan Avatar asked Jan 30 '12 07:01

Andy Wan


2 Answers

Yes this is possible. The documentation you cited is trying to say that if you have row keys 1..10, and you ask for a range of 5..8 you will not get a set of rows [5, 6, 7, 8].

This is the documentation for fetching all rows from a column family.

Basically you use get_range_slices with a start_key of empty string, and no end_key. Depending on the number of rows specified in count, this might return fewer than all rows in the column family. In that case you use the last row key from the previous result set as the start_key for your next query.

like image 125
psanford Avatar answered Nov 16 '22 17:11

psanford


Here is an example of doing this in Java with the Hector client (with multiple threads): https://github.com/zznate/cassandra-tutorial/blob/master/src/main/java/com/datastax/tutorial/KeyIteratorExample.java

like image 33
zznate Avatar answered Nov 16 '22 15:11

zznate