case question

29 views
Skip to first unread message

koen

unread,
Aug 22, 2016, 9:02:16 AM8/22/16
to Neo4j
Hi, i have created a neo4j graph database with formula 1 data based on data found on ergast.com developer api.
All well sofar. Now i want to use a multi line case kind of statement in cypher in order to do a match based on the content of a field in the input file but i cannot make the case statement to work.. the syntax is not correct as i get en error on the case statement  .. most of the code works but what would be the valid approach to create such a case statement in cypher ... ?

My cypher code looks like

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS
FROM "file:///incident.csv" AS line
MERGE (incident:Incident { id: TOINT(line.incidentId) })
SET incident.session = line.session, incident.allegation = line.allegation
SET incident.involving = line.`incident involving`, incident.outcome = line.outcome
SET incident.reason = line.reason, incident.notes = line.notes
WITH line,incident
CASE incident.session
    WHEN "R"  THEN MATCH (session:Session:R)-->(grandprix:GrandPrix {id: TOINT(line.raceId)})
    WHEN "Q1" THEN MATCH (session:Session:Q1)-->(grandprix:GrandPrix {id: TOINT(line.raceId)})
    WHEN "Q2" THEN MATCH (session:Session:Q2)-->(grandprix:GrandPrix {id: TOINT(line.raceId)})
    WHEN "Q3" THEN MATCH (session:Session:Q3)-->(grandprix:GrandPrix {id: TOINT(line.raceId)})
    WHEN "P1" THEN MATCH (session:Session:P1-->(grandprix:GrandPrix {id: TOINT(line.raceId)})
    WHEN "P2" THEN MATCH (session:Session:P2)-->(grandprix:GrandPrix {id: TOINT(line.raceId)})
    WHEN "P3" THEN MATCH (session:Session:P3)-->(grandprix:GrandPrix {id: TOINT(line.raceId)})
    END
MERGE (incident)-[:SESSION]->(session)


thanks koen


Michael Hunger

unread,
Aug 22, 2016, 10:45:58 AM8/22/16
to ne...@googlegroups.com
In general clauses are not supported within CASE only expressions.

Fortunately you can rewrite your query

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS
FROM "file:///incident.csv" AS line
MERGE (incident:Incident { id: TOINT(line.incidentId) })
SET incident.session = line.session, incident.allegation = line.allegation
SET incident.involving = line.`incident involving`, incident.outcome =
line.outcome
SET incident.reason = line.reason, incident.notes = line.notes
WITH line,incident
MATCH (session:Session)-->(grandprix:GrandPrix {id: TOINT(line.raceId)})
WHERE incident.session IN labels(session)
MERGE (incident)-[:SESSION]->(session)

> --
> You received this message because you are subscribed to the Google Groups
> "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to neo4j+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

Koen Kleingeld

unread,
Aug 23, 2016, 4:26:12 AM8/23/16
to ne...@googlegroups.com
hi michael , thanks !, will try it the other way around ..

reg Koen


> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Groeten / Best Regards,

Koen
Reply all
Reply to author
Forward
0 new messages