By this point, instead of looking for a universal solution, I'm trying to special-case it for the few places it's indispensable. But even so, hitting strange issues. In the query below, it works fine if I omit any one of the WITH sr_s UNWIND...
clause. But with all 3, I get a strange internal error:
ERROR 8668 --- [o4jDriverIO-2-2] ChannelErrorHandler : [0xb2f0fa0a][] Fatal error occurred in the pipeline
org.neo4j.driver.v1.exceptions.DatabaseException: ( _@334,RefSlot(2,true,Any)) (of class scala.Tuple2)
at org.neo4j.driver.internal.util.ErrorUtil.newNeo4jError(ErrorUtil.java:72) ~[neo4j-java-driver-1.7.0.jar:1.7.0-b583401e539a45fc508a79038cb6a85bdccbd9e5]
at org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher.handleFailureMessage(InboundMessageDispatcher.java:105) ~[neo4j-java-driver-1.7.0.jar:1.7.0-b583401e539a45fc508a79038cb6a85bdccbd9e5]
This on Neo4j 3.4.5-enterprise. And the query (may include fresh or existing nodes):
MATCH (sr_s:Space { uuid: {map}.selfMap.uuid })
SET sr_s += {map}.selfMap
WITH sr_s
UNWIND range(0, size({map}.aggregatedAxes) - 1) AS index
WITH sr_s, index, {map}.aggregatedAxes[index] AS axisMap
OPTIONAL MATCH (sr_s)-[A:AGGREGATES]->(a:Axis { uuid: axisMap.selfMap.uuid })
FOREACH (_ IN CASE WHEN a IS NULL THEN [true] ELSE [] END |
CREATE (sr_s)-[:AGGREGATES { order: index }]->(a2:Axis)
SET a2 += axisMap.selfMap
)
SET a += axisMap.selfMap, A += { order: index }
WITH sr_s
UNWIND {map}.projectedAxes AS axisMap
OPTIONAL MATCH (sr_s)-[:PROJECTS]->(a:Axis { uuid: axisMap.selfMap.uuid })
FOREACH (_ IN CASE WHEN a IS NULL THEN [true] ELSE [] END |
CREATE (sr_s)-[:PROJECTS]->(a2:Axis)
SET a2 += axisMap.selfMap
)
SET a += axisMap.selfMap
WITH sr_s
UNWIND {map}.points AS pointMap
OPTIONAL MATCH (sr_s)-[:CONTAINS]->(p:Point { uuid: pointMap.selfMap.uuid })
FOREACH (_ IN CASE WHEN p IS NULL THEN [true] ELSE [] END |
CREATE (sr_s)-[:CONTAINS]->(p2:Point)
SET p2 += pointMap.selfMap
)
SET p += pointMap.selfMap
WITH sr_s
OPTIONAL MATCH (sr_s)-[sr_AG:AGGREGATES]->(sr_ag:Axis)
OPTIONAL MATCH (sr_s)-[sr_PR:PROJECTS]->(sr_pr:Axis)
OPTIONAL MATCH (sr_s)-[sr_C:CONTAINS]->(pt_p:Point)
OPTIONAL MATCH (pt_p)-[pt_A:ALONG]->(pt_a:Axis)
OPTIONAL MATCH (sr_s)-[sr_P:PRESENTS]->(ir_i:Insight)
OPTIONAL MATCH (ir_i)-[ir_T:TITLED]->(ir_mdT:MessageDefinition)
OPTIONAL MATCH (ir_i)-[ir_S:STATES]->(ir_mdS:MessageDefinition)
OPTIONAL MATCH (ir_i)-[ir_AT:AT]->(pt_p:Point)
RETURN *
I tried ensuring the rel and node names were unique (despite the WITH); didn't help. All the <map>.selfMap
contain primitives or (in one case) array of primitives. Thanks for any insight!