cancel
Showing results for 
Search instead for 
Did you mean: 

Using variables in apoc.do.when function

dan3
Node Link

Hi,
I am trying to use "apoc.do.when" function, and I am probably doing something wrong.
Basically, We are trying to copy labels from one node to a group of nodes that meet a certain condition.

I want to run the SET command only if I found missing labels and I tried to do something like that:

MATCH(A:<label> {name:<name>}) 

MATCH(B:<label> {name:<name>})

CREATE(A)-[w0:data]->(B) 

WITH A, B, labels(A) as labelsA, labels(B) as labelsB WITH A, B, [uniqlabelsB in labelsB where not (uniqlabelsB in labelsA) and uniqlabelsB STARTS WITH 'group' | uniqlabelsB] as missingLabelsFromNode1, [uniqlabelsA in labelsA where not (uniqlabelsA in labelsB) and uniqlabelsA STARTS WITH 'group'  | uniqlabelsA] as missingLabelsFromNode2

CALL apoc.do.when(size(missingLabelsFromNode1) > 0,"MATCH(FA) where FA.family_name STARTS WITH A.family_name set FA:B.base_group", "", {A:A, B:B}) YIELD value

RETURN A,B

And I got this error message neo4j.exceptions.ClientError: Failed to invoke procedure apoc.do.when: Caused by: org.neo4j.exceptions.SyntaxException: Invalid input '.'

What am I doing wrong?
How can I get the base_group parameter from the B node and set it as a label for all the FA nodes?

I also tried to use the missingLabelsFromNode1 variable but it ignores from this parameter also.

Thanks in advance.

Dan

2 REPLIES 2

robert_quinn
Node Clone

Dan,

Can you provide Create statements to build a simple test case? I tried reproducing the issue, from the code, but can't.

Robert

clem
Graph Steward

I'm not sure, but it does seem unwise to have the fragment (A:A) and (B:B) since you are using the capital letter for both a Label and a variable for a node.

It's against the style guidelines and feels confusing to me.