Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-24-2020 12:34 PM
Hi, I am trying to add a new nodes for each WCC component and connect each alias node to it is component node. I am doing this with only one MATCH command and the UNWIND command - is this possible?
I tried
MATCH (n:alias)
with n.GraphProperty_wcc_throughTopic as component, COLLECT(n) as component_nodes
WITH component, component_nodes, size(component_nodes) as component_size
MERGE (comp :WCC_component {GraphProperty_wcc : component, GraphProperty_wcc_size : component_size})
with (UNWIND $component_nodes) as component_node, component
MERGE (comp) <-[:in_WCC]- (component_node)
but I keep getting some error related to UNWIND that I do not understand:
Neo.ClientError.Statement.SyntaxError: Invalid input 'a': expected whitespace, comment or a relationship pattern (line 5, column 30 (offset: 302))
"with UNWIND $component_nodes as component_node, component, size_component"
Thanks,
Lavanya
^
Solved! Go to Solution.
02-24-2020 05:40 PM
Hi again, you still have the UNWIND within the WITH clause:
with
UNWIND component_nodes as component_node
That said you WILL need a WITH clause between the MERGE and the UNWIND, but it can't be left blank like this, you need to include the variables that you want to keep in scope:
...
WITH component, component_nodes
UNWIND component_nodes as component_node
WITH component, component_node
MATCH (c :WCC_component {GraphProperty_wcc : component})
CREATE (c) <-[:in_WCC]- (component_node)
02-24-2020 02:06 PM
Try replacing
with (UNWIND $component_nodes) as component_node, component
with
UNWIND component_nodes as component_node
MERGE (comp) <-[:in_WCC]- (component_node
02-24-2020 05:03 PM
My query
MATCH (n:alias)
with n.GraphProperty_wcc_throughTopic as component, COLLECT(n) as component_nodes
WITH component, component_nodes, size(component_nodes) as component_size
MERGE (comp :WCC_component {GraphProperty_wcc : component, GraphProperty_wcc_size : component_size})
with
UNWIND component_nodes as component_node
WITH component, component_node
MATCH (c :WCC_component {GraphProperty_wcc : component})
CREATE (c) <-[:in_WCC]- (component_node)
also returned the same error
Neo.ClientError.Statement.SyntaxError: Invalid input 'm': expected 'n/N' (line 6, column 10 (offset: 287))
"UNWIND component_nodes as component_node"
On the other hand, the following query WITHOUT the UNWIND command gave me the desired effect:
MATCH (n:alias)
with n.GraphProperty_wcc_throughTopic as component, COLLECT(n) as component_nodes
WITH component, component_nodes, size(component_nodes) as component_size
CREATE (comp :WCC_component {GraphProperty_wcc : component, GraphProperty_wcc_size : component_size});
MATCH (n:alias)
with n.GraphProperty_wcc_throughTopic as component, n AS component_node
WITH component, component_node
MATCH (c :WCC_component {GraphProperty_wcc : component})
CREATE (c) <-[:in_WCC]- (component_node)
I am still wondering why the UNWIND command is throwing this error.
02-24-2020 05:40 PM
Hi again, you still have the UNWIND within the WITH clause:
with
UNWIND component_nodes as component_node
That said you WILL need a WITH clause between the MERGE and the UNWIND, but it can't be left blank like this, you need to include the variables that you want to keep in scope:
...
WITH component, component_nodes
UNWIND component_nodes as component_node
WITH component, component_node
MATCH (c :WCC_component {GraphProperty_wcc : component})
CREATE (c) <-[:in_WCC]- (component_node)
All the sessions of the conference are now available online