In which 'title', 'name', or 'price' columns may all have multiple values:
John;Mary A good book;A bad book $7;$20
Smith A book $20;$2
These are fake data, but just illustrate the situation. I actually came up with a solution like this:
CALL apoc.load.csv('Sports.csv')
yield map as row
MERGE (m:Coach {ID: row._ID})
ON CREATE SET m += row { .*, alias: split(row.alias, '|'), awards: split(row.awards, '|') }
ON MATCH SET m += row { .*, alias: split(row.alias, '|'), awards: split(row.awards, '|') }
RETURN count(m) as mcount
This requires me to specify the column names that need to be split, 'alias' & 'awards'. In order to do this, for each node type, I defined what possible columns that need this split operation, then in my code I can retrieve those predefined columns and use the cypher like above to do the conversion.
It would be great if I don't need to predefine the columns for this purpose.
Use split function for every column and it works.
Created a csv file:
_ID|name|title|price
1|John;Mary|A good book;A bad book|$7;$20
2|Smith|A|book|$20:$2
LOAD CSV WITH HEADERS FROM "file:///lingvisa.csv" AS row FIELDTERMINATOR "|"
with toInteger(row._ID) as ID, split (row.name, ';') as nme, split(row.title, ';') as title, split(row.price, ';') as price
merge (a:LV {id: ID, name: nme, title: title, price: price})
;
Result: