5

Is it possible in cassandra map to input different data types like if I have a table like

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

Now I want to insert values in this table like

(1,{'test':'test1'})
(2,{'a':1})
(3,{'c':2})
Aaron
  • 55,518
  • 11
  • 116
  • 132
Nipun
  • 4,119
  • 5
  • 47
  • 83

3 Answers3

8

The Cassandra Map type does not support values (or keys) of differing types. However, you could create a User Defined Type to handle that.

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)
Aaron
  • 55,518
  • 11
  • 116
  • 132
1

Instead of having map in you case have it as text (String) column which will save you lots of space. Keep data in JSON format by stringifying it.

Aftab
  • 938
  • 1
  • 9
  • 20
0

No Cassandra does not support like this feature .cassandra Map is like java map and we know that java also does not support this . we have pass all value in map according to datatype .