Map Data Type in Cassandra
Map type in Cassandra is used to store one related item to another item in key-value pair. To create Map type, you have to start with Map and then provide the two data types for items e.g Map<item1 data type,item 2 data type>Let's create a table tbs with columns Id, ParentName and Children. We will create Children column of Map type with items data type of date and text.
CQLSH:techbrotherstutorials>CREATE TABLE tbs
(
id INT PRIMARY KEY,
parentname TEXT,
children MAP<date,
text> );
Let's insert a record in table by using CQL insert statement. To insert data into Map Type, you have to use {key-pair value, key-pair value,.............}(
id INT PRIMARY KEY,
parentname TEXT,
children MAP<date,
text> );
CQLSH:techbrotherstutorials>INSERT INTO tbs
(
id,
parentname,
children
)
VALUES
(
1,
'Aamir',
{'2001-10-03':'Ali', '2002-10-03':'Rida'}
);
Select the data from table by using CQL Select statement.(
id,
parentname,
children
)
VALUES
(
1,
'Aamir',
{'2001-10-03':'Ali', '2002-10-03':'Rida'}
);