Insert multiple types into a map in cassandra

Is it possible to enter different data types in the cassandra map, for example, if I have a table like

(id int, value map<text,text>) 

Now I want to insert values ​​into this table, for example

 (1,{'test':'test1'}) (2,{'a':1}) (3,{'c':2}) 
+4
source share
3 answers

The Cassandra Map type does not support values ​​(or keys) of different types. However, you can create a Custom type to handle this.

 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) 
+4
source

Instead of having a map in your case, use it as a text column (String), which will save you a lot of space. Store data in JSON format, strict it.

0
source

No Cassandra does not support this feature. Kassandra Map is similar to a java map, and we know that java also does not support this. we transfer all values ​​on the map according to the data type.

0
source

All Articles