0

I am trying to put my domain model into Cassandra using CQL. Let's say I have USER_FAVOURITES table. Each favourites has ID as a PRIMARY KEY. I want to store the list of up to 10 records of multiple fields, field_name, field_location and so on in order.

Is this a good idea to model a table like this

CREATE TABLE USER_FAVOURITES (
    fav_id text PRIMARY KEY,
      field_name_list list<text>,
      field_location_list list<text>
);

And object is going to be constructed from list items of matching indicies (e.g.

Object(field_name_list[3],field_location_list[3]))

I query favourites always together. I may want to add and item to some position, start, end or middle.

Is this a good practice? Doesn't look like, but I am just not sure how to group objects in this case, also when i want to keep them in order by, for example, field_location or more complex ordering rule

Lyuben Todorov
  • 13,987
  • 5
  • 50
  • 69
i.petruk
  • 1,276
  • 1
  • 13
  • 18

2 Answers2

0

I'd suggest the following structure:

CREATE TABLE USER_FAVOURITES (
    fav_id text PRIMARY KEY,
    favs map<int, blob>
);

This would allow you to get access to any item via index. The value part of map is blob, as one can easily serialize a whole needed object into binary and deserialize later.

Scooletz
  • 183
  • 2
  • 7
-1

My personal suggestion will be don't emphasize too much on cassandra collection, as it is bloom further in future. Though above specified scenario is very much possible and no harm in doing so.

abhi
  • 4,762
  • 4
  • 29
  • 49
  • What do you mean by "bloom further in the future"? Do you mean more features will be added, or that collections may be removed? – Andrew Aug 24 '13 at 03:36
  • obviously new features will be added. say Generic type support – abhi Aug 24 '13 at 06:36