user1058797
user1058797

Reputation: 907

Cassandra Limit 10,20 clause

I am using Cassandra 1.2.3 and can execute select query with Limit 10.

If I want records from 10 to 20, I cannot do "Limit 10,20".

Below query gives me an error.

select * from page_view_counts limit 10,20 

How can this be achieved?

Thanks Nikhil

Upvotes: 10

Views: 9330

Answers (3)

Hardik Bhalani
Hardik Bhalani

Reputation: 863

sorry mate I did it using hector client & java,but seeing your requirement I can suggest to plan your data model like this : Use time span as a row key in yyyyMMddHH format,in that store column name as composite key made up of UTF8Type and TimeUUID (e.g C1+timeUUID ). note: here first composite key would be counter column family column name (e.g. C1) Now you will only store limited records say 20 in your CF and make this c1 counter 20,now if any new record came for the same timespan you have to insert that with key C2+timeUUID now u will increment counter column family c2 upto 20 records

Now to fetch record you just have to pass value C1 , C2 ...etc with rowkey like 2013061116 it will give you 20 records than another 20 and so on...you have to implement this programmatically..hope you got this and helps you

Upvotes: 0

Hardik Bhalani
Hardik Bhalani

Reputation: 863

for that you have to first plan your data model so that it can get records according to your requirement... Can you tell which sort of example your are doing? and Are you using hector client or any other ?

Upvotes: 0

Richard
Richard

Reputation: 11100

You can't do skips like this in CQL. You have have to do paging by specifying a start place e.g.

select * from page_view_counts where field >= 'x' limit 10;

to get the next 10 elements starting from x.

I wrote a full example in this answer: Cassandra pagination: How to use get_slice to query a Cassandra 1.2 database from Python using the cql library.

Upvotes: 13

Related Questions