在cassandra中的地图中插入多个类型

Nip*_*pun 5 cassandra cql3

是否可以在cassandra map中输入不同的数据类型,就像我有一个像这样的表

(id int, value map<text,text>)
Run Code Online (Sandbox Code Playgroud)

现在我想在这个表中插入值

(1,{'test':'test1'})
(2,{'a':1})
(3,{'c':2})
Run Code Online (Sandbox Code Playgroud)

Aar*_*ron 7

Cassandra Map类型不支持不同类型的值(或键).但是,您可以创建用户定义类型来处理它.

aploetz@cqlsh:stackoverflow2> CREATE TYPE testac (test text, a int, c int);

aploetz@cqlsh:stackoverflow2> CREATE TABLE testactable (
                                    key int, 
                                    values frozen<testac>,
                                    PRIMARY KEY (key));

aploetz@cqlsh:stackoverflow2> INSERT INTO testactable (key,values) 
                              VALUES (1,{test: 'test1', a: 1, c: 2});

aploetz@cqlsh:stackoverflow2> SELECT * FROm testactable ;

 key | values
-----+-----------------------------
   1 | {test: 'test1', a: 1, c: 2}

(1 rows)
Run Code Online (Sandbox Code Playgroud)