4

I have a data set in csv format. One of the fields is a type, like an enumeration. Based on this type I need to create different types nodes and relations when loading the data using csv load. You could call a row in the csv for a super type having an attribute defining its subtype.

I'm not really able to figure out how this can be done in cypher. Is my only option to split the one csv file into a csv file per type and run different cyphers ?

1 Answer 1

5

This document on conditional statements helps.

Here is a simple example for loading based on a column value:

Data: a,b Ford,car Chevy,truck Mazda,car GMC,truck F150,truck

Cypher code:

load csv with headers from "file:/testfile.csv" as row
FOREACH(ignoreMe IN CASE WHEN trim(row.b) = "truck" THEN [1] ELSE [] END | MERGE (p:Truck {vehicleType: row.a}))
FOREACH(ignoreMe IN CASE WHEN trim(row.b) = "car" THEN [1] ELSE [] END | MERGE (p:Car {vehicleType: row.a}))

When you are done, you will have nodes created of different types.

Sign up to request clarification or add additional context in comments.

2 Comments

Very useful trick! It's a pity Cypher doesn't support this directly, or does it?.
Ugliest hack to work with COMMERCIAL software that I have seen in a while. Where is the elegant solution from the Neo4j people?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.