Reputation: 4319
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})
Upvotes: 5
Views: 4970
Reputation: 938
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.
Upvotes: 1
Reputation: 38
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 .
Upvotes: 0
Reputation: 57808
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)
Upvotes: 8