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})
Use the UPDATE command to insert values into the map. Append an element to the map by enclosing the key-value pair in curly brackets and using the addition (+) operator. cqlsh> UPDATE cycling.
Use a map when pairs of related elements must be stored as a key-value pair. A map relates one item to another with a key-value pair. For each key, only one value may exist, and duplicates cannot be stored. Both the key and the value are designated with a data type.
Is insert and update same in Cassandra? Insert, Update, and Upsert Because Cassandra uses an append model, there is no fundamental difference between the insert and update operations. If you insert a row that has the same primary key as an existing row, the row is replaced.
A frozen value serializes multiple components into a single value. Non-frozen types allow updates to individual fields. Cassandra treats the value of a frozen type as a blob. The entire value must be overwritten.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With