I am fairly new to graph/neo4j/cypher and have my csv imports working well for nodes, but to build the relationships, I want to make it more dynamic by using a case statement to decide my relationship statement, but it errors out with:
Invalid input 'S': expected 'l/L' (line 2, column 3 (offset: 60)) "CASE line.type"
Is it possible to use CASE in this format or is my syntax wrong?
CSV File:
id,type,rack,name_from,port,name_to
1,fDEVICE,R01-01,ID_DEV_001,PX-01-0-F,R01-01-F-U01-1-A-01
2,fDEVICE,R01-01,ID_DEV_001,PX-01-1-F,R01-01-F-U02-1-A-01
3,fDEVICE,R01-01,ID_DEV_001,PX-03-0-F,R01-01-F-U01-1-A-02
4,fDEVICE,R01-01,ID_DEV_001,PX-03-1-F,R01-01-F-U02-1-A-02
5,FRAME,,R02-01-F-U01-1-A-01,,R02-01-F-U13-1-A-01
6,FRAME,,R02-12-F-U01-1-A-01,,R02-12-F-U24-1-A-01
7,FRAME,,R02-01-F-U01-1-A-02,,R02-01-F-U14-1-A-01
8,FRAME,,R02-12-F-U01-1-A-02,,R02-12-F-U23-1-A-01
9,tDEVICE,R03-01,ID_DEV_002,gi0-01,R03-01-F-U01-1-A-01
10,tDEVICE,R03-12,ID_DEV_003,gi0-01,R03-12-F-U02-1-A-01
11,tDEVICE,R03-02,ID_DEV_004,gi0-01,R03-02-F-U01-1-A-01
12,tDEVICE,R03-11,ID_DEV_005,gi0-01,R03-11-F-U02-1-A-01
Cypher:
LOAD CSV WITH HEADERS FROM 'file:///patching.csv' AS line
CASE line.type
WHEN 'fDEVICE' THEN
MATCH (deviceport:DevicePort { name: line.port, device: line.name_from }),(port:Port { name: line.name_to})
CREATE (port)-[:PATCHED]->(deviceport)
WHEN 'FRAME' THEN
MATCH (portA:Port { name: line.name_from}),(portB:Port { name: line.name_to})
CREATE (portA)-[:PATCHED]->(portB)
WHEN 'tDEVICE' THEN
MATCH (deviceport:DevicePort { name: line.port, device: line.name_from }),(port:Port { name: line.name_to})
CREATE (port)<-[:PATCHED]-(deviceport)
END