Importing data into a CQL map

Use the cql-import tool to map SQL columns to items in a map, similar to importing data into list and set.

You can use the cql-import tool to map SQL columns to items in a map, similar to importing data into list and set. You use the following cassandra-column-mapping parameter to import data into a map.
CQLCOL:[KEY1:SQLCOL1,KEY2:SQLCOL2,KEY3:SQLCOL3]
Note that there are no spaces after the comma (,) or the colon (:) in [KEY1:SQLCOL1,KEY2:SQLCOL2,KEY3:SQLCOL3].

This form of mapping maps SQL column data to map entries using the key name specified in the mapping. The SQL column names can be used as the key names by omitting the key from the mapping.

The mapping mechanism supports a mixed key name mapping.
CQLCOL:[KEY1:SQLCOL1,SQLCOL2,KEY3:SQLCOL3]

The following example shows how to import a MySQL table into a CQL map collection.

Suppose you have created and populated a MySQL table using the following commands:
mysql> CREATE TABLE sql_table (sqlid INTEGER PRIMARY KEY,  a VARCHAR(25), b VARCHAR(25), c VARCHAR(25)); 
mysql> INSERT INTO sql_table (sqlid, a, b, c) values (1, 'valuea', 'valueb', 'valuec');
mysql> INSERT INTO sql_table (sqlid, a, b, c) values (2, 'valued', 'valuee', 'valuef');
Using cqlsh, create the following table in Cassandra that corresponds to the MySQL table:
cqlsh> CREATE TABLE cql_table (cqlid int PRIMARY KEY, mymap maptext,text);
The following map along with other options imports the data into CQL:
--cassandra-column-mapping cqlid:sqlid,mymap:[key1:a,b,key3:c]
Note that there are no spaces after the comma (,) or the colon (:) in cqlid:sqlid,mymap:[key1:a,b,key3:c].

Querying Cassandra to select the table produces the following output:

 cqlid  | mymap                       
--------+-------------------------------------------------
 1      | {'key1':'valuea', 'b':'valueb', 'key3':'valuec'}
 2      | {'key1':'valued', 'b':'valuee', 'key3':'valuef'}