0

In my application I have lists which have items in them, they would look like that

1. list uuid: b1d19224-ebcc-4f69-a98e-4096a4b28121
 1. item
 2. item
 3. item

2. list uuid: 54b17b3a-5d83-4aec-9e7e-16bff1ba336b
 1. item

Those items are indexed by there numbers. What I would like to do is add items to those lists, but not just at the end of the list but sometimes also after a specific item for example after the first item.

The way I thought of doing that is by giving those items a unique id looking like that: (uuid of list).(number of item) for example b1d19224-ebcc-4f69-a98e-4096a4b28121.1. So every time I would like to add a new item it's either I would add it to the end of the list or after some item giving the rest of the items after that new an index+1 for example (uuid of list).(number+1).

  • Is there another way of accomplishing that, or should I do it like that?
  • This question doesn't seem to have anything to do with cassandra secondary indexes. Can you clarify? Also can you explain your key/column name/value proposal more clearly? See the "first model" in this post (http://stackoverflow.com/questions/3245267/column-family-concept-and-data-model) for a nice way of describing a column family with example data. – Martin Serrano Jul 26 '13 at 03:38
  • what I mean by that is that lists with their unique ids as keys are indexed but how would I save the items in a way that there would be an index on those items too, so that I could know which is the 3rd item or do operations like change their order easily. That's why I thought of giving the items a key of (uuid of list).(number of item) . Should I continue with this approach? If I do it this way can I easily ask the cassandra to give me for example all items in a list that have an index greater than 3 with a limit of 30? –  Jul 26 '13 at 06:18

1 Answers1

0

If you want to insert your items in your lists sorted on the unique item number, you should use CQL3 based composite primary keyed column family.

     create table list (
         partkey varchar,
         item_num int,
         id varchar,
         data varchar,
         PRIMARY KEY (partkey, item_num)
    ) with clustering order by (item_num desc);

Where the first part of primary key would server as the partition key and the second one serves as the sorting value. Have a look at the following link :

http://rollerweblogger.org/roller/entry/composite_keys_in_cassandra

Sayed Jalil Hassan
  • 2,535
  • 7
  • 30
  • 42
  • ok, what if I want to add an item for example after the 3rd item? This would have an id of 4 and the existing item that had an id of 4 would need to become 5. Can I select that existing item and change that id from 4 to 5? –  Jul 26 '13 at 06:23
  • Offcourse you can update an existing item. but keep in mind that variable that are part of primary key could not be updated directly; you will have to delete the corresponding entry first and re insert it. bw i dont think you would be able be achieve the auto increment thing with cassandra. You will have to manually update all entries. – Sayed Jalil Hassan Jul 26 '13 at 06:38