Inserting multiple types in map in cassandra
Asked Answered
M

3

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})
Monegasque answered 4/8, 2015 at 14:4 Comment(0)
S
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)
Screenplay answered 4/8, 2015 at 14:32 Comment(1)
Thanks, yes I know this, and this will not solve my problem at hand. Thank you anywaysMonegasque
F
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.

Flotage answered 18/8, 2015 at 21:33 Comment(0)
C
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 .

Cynthiacynthie answered 19/8, 2015 at 5:56 Comment(1)
Except Java has inheritance and you can have a value type of Object.Ananthous

© 2022 - 2024 — McMap. All rights reserved.