Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-27-2020 09:45 PM
`CALL apoc.load.xls('file:///filename.xlsx','Nodes') YIELD map as m
CALL apoc.create.node([m.fromNodeLabel], {name:m.fromNodeName,value:m.fromValue,instanceID:m.InstanceID}) YIELD node as f
CALL apoc.merge.node.eager([m.toNodeLabel], {name:m.toNodeName,instanceID:m.InstanceID}) YIELD node as t
CALL apoc.create.relationship(f,m.relship,{weight:10}, t)`
Variables YIELDed by the Create & Merge statements cannot be passed into the create.relationship statement without...something...?
Solved! Go to Solution.
02-28-2020 03:43 AM
Hi warwick,
Please mention Yield for apoc.create.relationship(f,m.relship,{weight:10}, t)
i.e.,
CALL apoc.load.xls('file:///filename.xlsx','Nodes') YIELD map as m CALL
CALL apoc.create.node([m.fromNodeLabel], {name:m.fromNodeName,value:m.fromValue,instanceID:m.InstanceID}) YIELD node as f
CALL apoc.create.node([m.toNodeLabel], {name:m.toNodeName,instanceID:m.InstanceID}) YIELD node as t
CALL apoc.create.relationship(f,m.relship,{weight:10}, t) yield rel as rel return rel,f,t
02-28-2020 12:53 AM
warwick ,
could you please share the error you are getting .
02-28-2020 03:43 AM
Hi warwick,
Please mention Yield for apoc.create.relationship(f,m.relship,{weight:10}, t)
i.e.,
CALL apoc.load.xls('file:///filename.xlsx','Nodes') YIELD map as m CALL
CALL apoc.create.node([m.fromNodeLabel], {name:m.fromNodeName,value:m.fromValue,instanceID:m.InstanceID}) YIELD node as f
CALL apoc.create.node([m.toNodeLabel], {name:m.toNodeName,instanceID:m.InstanceID}) YIELD node as t
CALL apoc.create.relationship(f,m.relship,{weight:10}, t) yield rel as rel return rel,f,t
02-28-2020 09:27 PM
That did it - I did not realise you must include a YIELD on the APOC create.
THANK YOU!
02-29-2020 09:09 AM
If you are running a procedure all by itself then you don't need to do yield. If you are using somewhere in the middle of a cypher query you need to do yield.
02-29-2020 02:03 PM
This may sound like a stupid question - but how do we know exactly what is yielded by these calls? I could not find it in http://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/nodes-relationships/data-creation/
02-29-2020 03:19 PM
Please go through this link for YIELD https://neo4j.com/docs/cypher-manual/current/clauses/call/
If you need to use the output of a procedure use Yield. This use could be in Return statement or in other query etc.
Procedure apoc.create.relationship can just give you output node or relationship and that is what I did. In the neo4j documentation details of Yield is only given for generic procedures like CALL apoc.create.uuids(count) YIELD uuid, row.
02-29-2020 03:19 PM
There are 2 types of extensions in apoc.
Functions and Procedures.
Please see the documentation here
https://neo4j.com/docs/labs/apoc/current/overview/
Functions - They are inline functions that can return a single value.
Ex: apoc.node.degree.in
Functions can be used in where conditions, WITH etc.
Ex:
MATCH (n) WHERE apoc.node.degree.in(n, 'NEXT') > 0
This query returns all the nodes which has more than one incoming NEXT relationship.
Procedures:
These can return more than one values. Those values are handled using YIELD.
If you search in the doc you can find signature as
apoc.create.relationship(from :: NODE?, relType :: STRING?, props :: MAP?, to :: NODE?) :: (rel :: RELATIONSHIP?)
You can see the return value here as only one (rel :: RELATIONSHIP?)
Hope this explains it better.
02-28-2020 09:24 PM
Procedure call inside a query does not support naming results implicitly (name explicitly using YIELD
instead) (line 4, column 1 (offset: 294))
"CALL apoc.create.relationship(f,m.relship,{weight:10}, t)"
^
All the sessions of the conference are now available online