3

I'm working on web application which should use Apache Cassandra to store data in. I need to store rating for each item and then get list of items with highest rating.

So the task - to store some additional info for items in sorted order to get rid of client side ordering or ordering using ORDER BY.

One of the possible options is to create index Column Family:

userId {
    100_ItemId1 : null, 
    90__ItemId2 : null,
    80__ItemId3 : null,
    80__ItemId4 : null
}

Note: userId is a key of the row, 100, 90, 80 - are rating values

But here is an issue with deleting, we should know previous rating value to remove index, an it can require to store reversed info in Column Family:

reversed_userId{
   ItemId1 : 100_ItemId1, 
   ItemId2 : 100_ItemId2,
   ...
}

Could you please say are there some patterns to store ordered items effectively?

P.S: I'm not going to use OrderPreservingPartitioner since it can be applied to whole KeySpace and it can damage load balancing and performance.

3
  • 1
    How many items are there? What's the relative frequency of inserts, deletes and queries? Aug 23, 2012 at 22:47
  • 1
    See this answer, as it is similar enough as to give you the right idea.
    – rs_atl
    Aug 28, 2012 at 19:30
  • @ChrisGerken Quantity of items: ~ 50 items per user, so there are ~50 column in each row. Quantity of inserts: ~ 10 per day. Quantity of queries: ~2000-5000 max per day. Quantity of deletes: ~5-10 per day. Also, the quantity of users is ~ 10 000 - 20 000. Sep 4, 2012 at 12:24

1 Answer 1

0

I'm hoping you'll be happy to know that in CQL 3 you can use composite key structure to sort now.

http://www.datastax.com/dev/blog/whats-new-in-cql-3-0

So for example:

 CREATE TABLE SortedPosts (
     post_id int,
     sort_order int,
     post_title text,
     PRIMARY KEY(post_id, sort_order)
 );

sort_order will sort it. And you can:

SELECT * FROM SortedPosts WHERE post_id = 1 ORDER BY sort_order ASC
SELECT * FROM SortedPosts WHERE post_id = 1 ORDER BY sort_order DESC

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.