1

when i create table in cassandra 2.0 using phpcassa,i got the error as follows

 Fatal error: Uncaught exception 'cassandra\InvalidRequestException' with message 'line 2:25 mismatched input 'map' expecting set null' in /var/www/assignment1/lib/thrift/Thrift.php:574

my code goes as

 $raw->client->execute_cql_query("CREATE TABLE 
mc_user(mc_user_id uuid primary key ,mc_user_email varchar,mc_user_pwd varchar,mc_status varchar,mc_user_type map<varchar,varchar>)", Compression::NONE);

if it doesnt supports does anyone can give me alternative solution for one to many relation?

Haseeb
  • 2,214
  • 1
  • 22
  • 43
Anju
  • 53
  • 5

2 Answers2

0

Collections are definitely supported in Cassandra since version 1.2 - I don't know PHP Cassa however your statement looks correct so I'd look on the client side for the solution.

An alternative could be using a composite key in which the second part of the key is the key you wanted use in the map

CREATE TABLE mc_user(
    mc_user_id uuid,
    themapkey varchar,
    mc_user_email varchar static,
    mc_user_pwd varchar static,
    mc_status varchar static,
    themapvalue varchar,
    PRIMARY KEY (mc_user_id, themapkey) 
);

Now instead of having one entry per user with a map, you have many entries per user. I've made the email, password and status static since they should be the same for each mc_user_id (two main advantages comes in my mind: they are not replicated in each row so they won't waste disk space and you can update them easily just with 1 update statement since static columns are accessible only by partition key).

You can still retrieve user's information (now static) only with mc_user_id

select mc_user_email, mc_status from mc_user where mc_user_id=some_id

You can retrieve a "map" entry with mc_user_id, themapkey

select themapvalue from mc_user where mc_user_id=some_id and themapkey=some_key

You can also easily rebuild all map with a select *

select * from mc_user where mc_user_id=some_id

HTH Cheers, Carlo

Carlo Bertuccini
  • 19,615
  • 3
  • 28
  • 39
0

Can try to use this library. It does not require Trift and works using the binary protocol.

evseevnn
  • 61
  • 1
  • 3