Reputation: 3572
there is one post for copying multi-value data like list and set from csv to cassandra table,
Import CSV with multi-valued (collection) attributes to Cassandra
has any one done this for map type data?
Upvotes: 1
Views: 1596
Reputation: 57748
Sure, I'll give you a simple example that uses both a map
and a list
. Consider the following table designed to hold starship data, as well as a list of crew and passengers:
CREATE TABLE shipregistry (
name text,
class text,
hullnumber text,
crew map<text,text>,
passengers list<text>,
PRIMARY KEY ((name))
);
I will load this table's data from the following text file (/home/aploetz/shipregistry_20150302.csv
), which has a header and a single row of pipe-delimited data:
name|class|crew|hullnumber|passengers
Serenity|03-K64-Firefly|{'1st Officer': 'Zoey Washburne', 'captain': 'Malcolm Reynolds', 'engineer': 'Kaylee Frye', 'pilot': 'Hoban Washburne'}|G-82659|['Simon Tam', 'River Tam', 'Derial Book', 'Inara Serra']
I will then import it using the cqlsh COPY
command:
aploetz@cqlsh:presentation> COPY shipregistry FROM
'/home/aploetz/shipregistry_20150302.csv' WITH HEADER=true and DELIMITER='|';
1 rows imported in 0.017 seconds.
Important to note, is that the list
data for the passengers
column, is comma-delimited and enclosed in brackets:
['Simon Tam', 'River Tam', 'Derial Book', 'Inara Serra']
Likewise, the map
data for the crew
column, is a comma-delimited list of key-value pairs and enclosed in braces:
{'1st Officer': 'Zoey Washburne', 'captain': 'Malcolm Reynolds', 'engineer': 'Kaylee Frye', 'pilot': 'Hoban Washburne'}
I chose a pipe as a delimiter to make this easier on myself and avoid potential clashes with commas in the collection types.
Upvotes: 5