neoman1
neoman1

Reputation: 127

Neo4j Cypher: How to convert mysql table to graph nodes for given sample?

MySQL Table with Columns Names as (Name, Value):

Name Value

A    V100
B    V200
C    V300
A    V101
B    V202
C    V301

How do we convert the above table to graph: Labels should be as follows:

Label A
Label B
Label C 
Nodes (a:A{V100}),(a:A{V101}) 
      (b:B{V200}),(b:B{V201}) 
      (c:C{V00}), (c:C{V301})

The Problem is that in the table the value A, B, C are generic. In future any other values may be added like D with values V400 & V401 or E with values V500 & V501.

Hence, the cypher query should be generic in order to create the nodes.

Upvotes: 1

Views: 213

Answers (1)

Gabor Szarnyas
Gabor Szarnyas

Reputation: 5047

Vanilla Cypher does not support creating dynamic labels, so you'll need the APOC library.

LOAD CSV WITH HEADERS FROM "file:/some-file.csv" AS line
CALL apoc.create.node([line.Name], {value: line.Value})
YIELD node
RETURN count(node)

For a guide on LOAD CSV, check out this blogpost and also the Cypher documentation

Upvotes: 1

Related Questions