jsoncassandracql3

Cassandra + data insertion + set<FROZEN<map<text,text>>>


My column family structure is:

create table mykeyspc."test" (
id int PRIMARY KEY,
val set<frozen<map<text,text>>>
);

when I am inserting data through CQL shell

insert into "test" JSON '{"id":1,"val":{"ab","bc"}}';
Error: INVALIDREQUEST: code=2200 [Invalid query] message="Counld not decode JSon string as 
map:org.codehaus.jackson.jsonParseException: Unexpected character{'{'{ code 123}) 

or

insert into "test" (id,val) values (1,{{'ab','bc'},{'sdf','name'}});
Error: INVALIDREQUEST: code=2200 [Invalid query] message="INVALID SET LITERAL FOR
VAL:value{'a','b'} is not of type frozen<map<text,text>>"

Solution

  • In your second example, try separating the map key/values with colons : instead of commas.

    aploetz@cqlsh:stackoverflow> INSERT INTO mapOfSet (id,val) 
                                 VALUES (1,{{'ab':'bc'},{'sdf':'name'}});
    aploetz@cqlsh:stackoverflow> SELECT * FROm mapofset WHERE id=1;
    
     id | val
    ----+---------------------------------
      1 | {{'ab': 'bc'}, {'sdf': 'name'}}
    
    (1 rows)