0

I am trying to update a value stroed in map of given key using cql. Can anyone tell me how to do it? The following is my table:

create table game(game_id uuid, game_name text, participant_id_name map<uuid, text>, PRIMARY KEY (game_id));
create index on game(participant_id_name);

Now I have a given participant's uuid and want to update his/her name, but I dont know the game_id. I wonder how can I check if the participant belongs to participant_id_name column and then update the name.

Rahul Kadukar
  • 858
  • 3
  • 15
  • 35
Jennifer He
  • 75
  • 1
  • 2
  • 10

1 Answers1

0

I do not believe your data model is optimal given what you are trying to do, so I am proposing the following:

create table game(game_id uuid, game_name text, participant_id int, participant_id_name text, PRIMARY KEY (game_id), participant_id);

With this table, you have a partition key of game_id and a clustering column of participant_id, so the partition will include everything for the game_id ordered by the participant_id column. I believe this makes sense for what you are trying to do. Instead of using a database generated unique id for the participant_id, I suggest having the application provide an integer when inserting the name of the person so you know both pieces of data.

(Please note I do not have complete information, and am making a best effort with the information provided.)

Chris Gerlt
  • 647
  • 4
  • 10
  • Thanks very much for your help :)I think your recommendation is better than what I had. Could you elaborate why using PRIMARY KEY (game_id), participant_id) is better than using map type? Thanks. – Jennifer He Sep 11 '15 at 16:41
  • I'm making a best guess, to be honest. You should read this: http://www.datastax.com/dev/blog/basic-rules-of-cassandra-data-modeling and think about the queries you want to perform. That should help build a data model. Its possible a map will be fine but designing with a requirement to read-then-write is a definite anti-pattern to avoid. – Chris Gerlt Sep 11 '15 at 16:55
  • Thanks very much for your link! – Jennifer He Sep 11 '15 at 20:13