Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra/Pycassa: Getting random rows

Is there a possibility to retrieve random rows from Cassandra (using it with Python/Pycassa)?

Update: With random rows I mean randomly selected rows!

like image 319
Bernhard Vallant Avatar asked Feb 16 '26 08:02

Bernhard Vallant


1 Answers

You might be able to do this by making a get_range request with a random start key (just a random string), and a row_count of 1.

From memory, I think the finish key would need to be the same as start, so that the query 'wraps around' the keyspace; this would normally return all rows, but the row_count will limit that.

Haven't tried it but this should ensure you get a single result without having to know exact row keys.

like image 119
DNA Avatar answered Feb 17 '26 22:02

DNA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!