Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get last record in Cassandra

Tags:

cassandra

Have a table with about 20 million rows in Cassandra.

The table is ordered by a primary_key column, which is a string. We are using 'ByteOrderedPartitioner', so the rows are ordered by the primary_key and not a hash of the primary_key column.

What is a good way to get the very last record in the table?

Thanks so much!

like image 360
Chris Dutrow Avatar asked Nov 13 '22 04:11

Chris Dutrow


1 Answers

If for "very last record" you mean the one ordered as last I don't think you can do it like a "GET", you have to scan rows. The best you can do, afaik, is select a good range to scan (good start key) according to your primary key.

From datastax docs:

"Using the ordered partitioner allows ordered scans by primary key. This means you can scan rows as though you were moving a cursor through a traditional index. For example, if your application has user names as the row key, you can scan rows for users whose names fall between Jake and Joe. This type of query is not possible using randomly partitioned row keys because the keys are stored in the order of their MD5 hash (not sequentially)."

If you find better solution let me know.

Regards, Carlo

like image 50
Carlo Bertuccini Avatar answered Nov 15 '22 13:11

Carlo Bertuccini