Cassandra +数据插入+设置<frozen <map <text,text>&gt;&gt;

时间:2015-10-28 15:18:33

标签: json cassandra datastax-enterprise cql3

我的列族结构是:

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

当我通过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}) 

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>>"

1 个答案:

答案 0 :(得分:5)

在第二个示例中,尝试使用冒号:而不是逗号分隔地图键/值。

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)