neo4j-contrib / neo4j-apoc-procedures

Awesome Procedures On Cypher for Neo4j - codenamed "apoc"                     If you like it, please ★ above ⇧            
https://neo4j.com/labs/apoc
Apache License 2.0
1.69k stars 495 forks source link

Generated cypher by `apoc.export.cypher.query` showing Merge on the basis of different properties instead of using the unique constraint #2226

Closed lovepreetkaur3395 closed 2 years ago

lovepreetkaur3395 commented 2 years ago

Generated cypher by apoc.export.cypher.query showing Merge on the basis of different properties instead of using the unique constraint

Expected Behavior (Mandatory)

Why are the MERGEd nodes mathced this way (n:UNIQUE IMPORT LABEL{UNIQUE IMPORT ID:3131}) instead of merging them over the orginal labels and properties? I am trying to see if I could run the resulting query from the call to apoc.export.cypher.query over the original graph and get the original graph to be updated with that query. What it does instead is recreating the complete graph aside of the original one.

Actual Behavior (Mandatory)

Merge should be on the basis of unique constraint.

How to Reproduce the Problem

I am currently executing below cypher:

CALL apoc.export.cypher.query('MATCH (n)-[r]->(m) RETURN n,r,m LIMIT 2','',{format:'plain', cypherFormat:'updateAll'}) YIELD cypherStatements
RETURN cypherStatements

Results of query: cypherStatements

"MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:3131}) SET n.`timePeriod`="1-3 years", n:`Urgency`, n:`_HorizonScanning`;
MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:5578}) SET n.`created`="2019-01-30T08:17:35Z", n.`createdBy`="Fabien Batejat [FBATEJAT]", n.`indicator`=["Number of CDOs"], n.`lastUpdate`="2019-08-30T09:40:34.751Z", n.`sourceLink`=["https://www.visualcapitalist.com/the-rise-of-the-chief-data-officer-cdo/"], n.`sourceTitle`=["Visual Capitalist"], n.`status`="Active", n.`updatedBy`="Batejat, Fabien [FBATEJAT]", n:`Topic`, n:`_HorizonScanning`;
MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:5769}) SET n.`created`="2019-02-07T10:59:51Z", n.`createdBy`="Simona Arminaité [SARMAIN]", n.`indicator`=["AI development "], n.`lastUpdate`="2019-06-28T14:14:47.893Z", n.`sourceLink`=["https://a16z.com/2018/12/03/when-ai-is-the-product-the-rise-of-ai-based-consumer-apps/"], n.`sourceTitle`=["Anreessen Horowitz - Software Is Eating the World"], n.`status`="Active", n.`title`="AI as a consumer product​", n.`updatedBy`="Batejat, Fabien [FBATEJAT]", n:`Topic`, n:`_HorizonScanning`;
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
MATCH (n1:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:5769}), (n2:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:3131}) MERGE (n1)-[r:`EXHIBITS`]->(n2) SET r.`status`="Active";
MATCH (n1:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:5578}), (n2:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:3131}) MERGE (n1)-[r:`EXHIBITS`]->(n2) SET r.`status`="Active";
MATCH (n:`UNIQUE IMPORT LABEL`) WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
"

Specifications (Mandatory)

Why are the MERGEd nodes mathced this way (n:UNIQUE IMPORT LABEL{UNIQUE IMPORT ID:3131}) instead of merging them over the orginal labels and properties? I am trying to see if I could run the resulting query from the call to apoc.export.cypher.query over the original graph and get the original graph to be updated with that query. What it does instead is recreating the complete graph aside of the original one.

Currently used versions

Versions

jexp commented 2 years ago

Actually the main issue is that the source graph has multiple labels, and only one of the labels has a unique constraint.

You forgot to mention this crucial bit of information :)

lovepreetkaur3395 commented 2 years ago

Actually the main issue is that the source graph has multiple labels, and only one of the labels has a unique constraint.

You forgot to mention this crucial bit of information :)

Oops, My bad !!!

vga91 commented 2 years ago

@lovepreetkaur3395 I tried to reproduce the issue, with a simple 3-label query

CREATE (f:Foo {name:'foo', born:date('2018-10-31')})-[:KNOWS {since:2016}]->(b:Bar {name:'bar',age:42}),(c:Bar {age:12}), (:Another)

and a CREATE CONSTRAINT ON ( bar:Bar ) ASSERT bar.age IS UNIQUE.

With this procedure:

CALL apoc.export.cypher.query("MATCH (n)-[r]->(m) RETURN n,r,m","",
{useOptimizations: {type: "none"}, format: "plain", cypherFormat: "updateAll"})
YIELD cypherStatements RETURN cypherStatements

i receive this one (so it leverages the constraint):

MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:0}) SET n.born=date('2018-10-31'), n.name="foo", n:Foo;
MERGE (n:Bar{age:42}) SET n.name="bar";
CREATE CONSTRAINT ON (node:Bar) ASSERT (node.age) IS UNIQUE;
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
MATCH (n1:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:0}), (n2:Bar{age:42}) MERGE (n1)-[r:KNOWS]->(n2) SET r.since=2016;
MATCH (n:`UNIQUE IMPORT LABEL`)  WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;

Can you try with the latest apoc version (3.5.0.12), and, in case the problem is still present, can you provide a simple dataset to reproduce it?

lovepreetkaur3395 commented 2 years ago

I have asked customer to send the dummy dataset to reproduce this issue.

lovepreetkaur3395 commented 2 years ago

Customer won't be able to share the data with us unfortunately. Is there an easy way to retrieve an anonymized relevant subgraph from their database so that you could reconstruct it on your end and test?

lovepreetkaur3395 commented 2 years ago

@vga91 Customer won't be able to share the data with us unfortunately. Is there an easy way to retrieve an anonymized relevant subgraph from their database so that you could reconstruct it on your end and test?

vga91 commented 2 years ago

@lovepreetkaur3395 A general way to export part of the graph obfuscating the data (without changing it in the original database) is the following, in which I change ALL the properties, present in the first 50 path, with a uuid and create a exportFile.json:

match path=(n)-[]->() with path limit 50
with nodes(path) as nodes, relationships(path) as rels
with apoc.coll.toSet(apoc.coll.flatten(collect(nodes))) as nodes, apoc.coll.toSet(apoc.coll.flatten(collect(rels))) as rels
call apoc.cypher.doIt('unwind $nodes as node1
WITH apoc.create.virtual.fromNode(node1, keys(node1)) as nVirtual
call apoc.create.setProperties(nVirtual, keys(apoc.any.properties(nVirtual)), apoc.coll.fill(apoc.create.uuid(), size(keys(apoc.any.properties(nVirtual))))) 
yield node as n2 return collect(n2) as nodesUpdated
', {nodes: nodes})
YIELD value
WITH value["nodesUpdated"] as nodesUpdated, rels
call apoc.cypher.doIt('unwind $rels as rel1
WITH apoc.create.vRelationship(startNode(rel1), type(rel1), properties(rel1), endNode(rel1)) as relV
call apoc.create.setRelProperties(relV, keys(apoc.any.properties(relV)), apoc.coll.fill(apoc.create.uuid(), size(keys(apoc.any.properties(relV))))) 
yield rel as rel2 return collect(rel2) as relsUpdated
', {rels: rels})
YIELD value WITH nodesUpdated, value["relsUpdated"] as relsUpdated
call apoc.export.json.data(nodesUpdated, relsUpdated, "exportFile.json", {}) YIELD file RETURN file

and then export the schema in another file schema.cypher:

call apoc.export.cypher.schema("schema.cypher")
jexp commented 2 years ago

The problem is that nodes have multiple labels, only one of tose labels has a constraint and we pick the wrong label when exporting and don't see the constraint we should always choose a main label if htere are multiple that has a constraint and not a random one.

vga91 commented 2 years ago

@jexp I might be wrong, but the problem seems to be not present in newer version.

In fact, with apoc 3.5.0.6, If I create a dataset

CREATE (f:Alpha:Bar:Beta:Gamma {name:'foo', born:date('2018-10-31')})-[:KNOWS {since:2016}]->(b:Foo {name:'bar',age:42});
CREATE (f:Delta:Epsilon:Bar:Iota {name:'foo2', born:date('2019-10-31')})-[:KNOWS {since:1999}]->(b:Foo {name:'fff',age:77});

a constraint CREATE CONSTRAINT ON (bar:Bar) ASSERT bar.name IS UNIQUE,

and I execute:

CALL apoc.export.cypher.query("MATCH (n)-[r]->(m) RETURN n,r,m","",
{useOptimizations: {type: "none"}, format: "plain", cypherFormat: "updateAll"})
YIELD cypherStatements RETURN cypherStatements

I receive a result with extraUNIQUE IMPORT LABEL:

"MERGE (n:Bar:`UNIQUE IMPORT LABEL`{name:"foo2", `UNIQUE IMPORT ID`:101}) SET n.born=date('2019-10-31'), n:Delta, n:Epsilon, n:Iota;
MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:102}) SET n.name="fff", n.age=77, n:Foo;
MERGE (n:Bar:`UNIQUE IMPORT LABEL`{name:"foo", `UNIQUE IMPORT ID`:155}) SET n.born=date('2018-10-31'), n:Alpha, n:Beta, n:Gamma;
MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:156}) SET n.name="bar", n.age=42, n:Foo;
CREATE CONSTRAINT ON (node:Bar) ASSERT (node.name) IS UNIQUE;
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
MATCH (n1:Bar:`UNIQUE IMPORT LABEL`{name:"foo2", `UNIQUE IMPORT ID`:101}), (n2:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:102}) MERGE (n1)-[r:KNOWS]->(n2) SET r.since=1999;
MATCH (n1:Bar:`UNIQUE IMPORT LABEL`{name:"foo", `UNIQUE IMPORT ID`:155}), (n2:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:156}) MERGE (n1)-[r:KNOWS]->(n2) SET r.since=2016;
MATCH (n:`UNIQUE IMPORT LABEL`)  WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
"

Instead with this dataset:

CREATE (f:Bar {name:'foo', born:date('2018-10-31')})-[:KNOWS {since:2016}]->(b:Foo {name:'bar',age:42});
CREATE (f:Bar {name:'foo2', born:date('2019-10-31')})-[:KNOWS {since:1999}]->(b:Foo {name:'fff',age:77});

I receive:

"MERGE (n:Bar{name:"foo"}) SET n.born=date('2018-10-31');
MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:102}) SET n.name="bar", n.age=42, n:Foo;
MERGE (n:Bar{name:"foo2"}) SET n.born=date('2019-10-31');
MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:158}) SET n.name="fff", n.age=77, n:Foo;
CREATE CONSTRAINT ON (node:Bar) ASSERT (node.name) IS UNIQUE;
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
MATCH (n1:Bar{name:"foo"}), (n2:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:102}) MERGE (n1)-[r:KNOWS]->(n2) SET r.since=2016;
MATCH (n1:Bar{name:"foo2"}), (n2:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:158}) MERGE (n1)-[r:KNOWS]->(n2) SET r.since=1999;
MATCH (n:`UNIQUE IMPORT LABEL`)  WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
"

With apoc 3.5.0.12, I get with the first dataset this result:

"MERGE (n:Bar{name:"foo2"}) SET n.born=date('2019-10-31'), n:Delta, n:Epsilon, n:Iota;
MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:102}) SET n.name="fff", n.age=77, n:Foo;
MERGE (n:Bar{name:"foo"}) SET n.born=date('2018-10-31'), n:Alpha, n:Beta, n:Gamma;
MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:158}) SET n.name="bar", n.age=42, n:Foo;
CREATE CONSTRAINT ON (node:Bar) ASSERT (node.name) IS UNIQUE;
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
MATCH (n1:Bar{name:"foo2"}), (n2:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:102}) MERGE (n1)-[r:KNOWS]->(n2) SET r.since=1999;
MATCH (n1:Bar{name:"foo"}), (n2:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:158}) MERGE (n1)-[r:KNOWS]->(n2) SET r.since=2016;
MATCH (n:`UNIQUE IMPORT LABEL`)  WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
"

The second one is equivalent to 3.5.0.6 result.

lovepreetkaur3395 commented 2 years ago

@vga91 , I am attaching the files provided by customer here ApocExport.zip .

vga91 commented 2 years ago

@lovepreetkaur3395 I confirm the above. With apoc 3.5.0.12 the problem seems to be not present. That is, after importing the two files into the zip, if I execute:

CALL apoc.export.cypher.query("MATCH (n)-[r]->(m) RETURN n,r,m LIMIT 5","",
{useOptimizations: {type: "none"}, format: "plain", cypherFormat: "updateAll"})
YIELD cypherStatements RETURN cypherStatements

with apoc 3.5.0.6 it's returned:

"MERGE (n:Person{cdsid:"1f40a365-1843-487f-89f8-8fdd7addedf5"}) SET n.active="1f40a365-1843-487f-89f8-8fdd7addedf5", n.created="1f40a365-1843-487f-89f8-8fdd7addedf5", n.email="1f40a365-1843-487f-89f8-8fdd7addedf5", n.jobTitle="1f40a365-1843-487f-89f8-8fdd7addedf5", n.name="1f40a365-1843-487f-89f8-8fdd7addedf5", n.neo4jImportId="5606", n.officeLocation="1f40a365-1843-487f-89f8-8fdd7addedf5", n.synced="1f40a365-1843-487f-89f8-8fdd7addedf5", n.unifyAccess="1f40a365-1843-487f-89f8-8fdd7addedf5", n.unifyUser="1f40a365-1843-487f-89f8-8fdd7addedf5", n.viraActive="1f40a365-1843-487f-89f8-8fdd7addedf5";
MERGE (n:Team:`UNIQUE IMPORT LABEL`{id:"3709d610-46b1-46d0-9f10-b1ca0f492e8a", `UNIQUE IMPORT ID`:102}) SET n.name="3709d610-46b1-46d0-9f10-b1ca0f492e8a", n.neo4jImportId="6372829", n.synced="3709d610-46b1-46d0-9f10-b1ca0f492e8a", n:_Vira;
MERGE (n:Team:`UNIQUE IMPORT LABEL`{id:"3376c40e-8fa3-4708-aa08-bef1783f40d1", `UNIQUE IMPORT ID`:113}) SET n.name="3376c40e-8fa3-4708-aa08-bef1783f40d1", n.neo4jImportId="9777303", n.synced="3376c40e-8fa3-4708-aa08-bef1783f40d1", n:_Vira;
MERGE (n:Person{cdsid:"c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b"}) SET n.active="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.created="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.email="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.jobTitle="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.name="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.neo4jImportId="15302", n.officeLocation="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.synced="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.unifyAccess="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.unifyUser="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.viraActive="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b";
MERGE (n:Team:`UNIQUE IMPORT LABEL`{id:"06455ff9-93dc-4ce2-b3a5-411983cb14ef", `UNIQUE IMPORT ID`:115}) SET n.name="06455ff9-93dc-4ce2-b3a5-411983cb14ef", n.neo4jImportId="14474", n.`r&d_2.0`="06455ff9-93dc-4ce2-b3a5-411983cb14ef", n.synced="06455ff9-93dc-4ce2-b3a5-411983cb14ef", n:_Vira;
MERGE (n:Project:`UNIQUE IMPORT LABEL`{id:"d9202f0c-8737-46e7-9d07-9ea741d98521", `UNIQUE IMPORT ID`:117}) SET n.artId="d9202f0c-8737-46e7-9d07-9ea741d98521", n.carWeaverName="d9202f0c-8737-46e7-9d07-9ea741d98521", n.carWeaverType="d9202f0c-8737-46e7-9d07-9ea741d98521", n.key="d9202f0c-8737-46e7-9d07-9ea741d98521", n.name="d9202f0c-8737-46e7-9d07-9ea741d98521", n.neo4jImportId="114933", n.`r&d_2.0`="d9202f0c-8737-46e7-9d07-9ea741d98521", n.streamPage="d9202f0c-8737-46e7-9d07-9ea741d98521", n.syncRequested="d9202f0c-8737-46e7-9d07-9ea741d98521", n.synced="d9202f0c-8737-46e7-9d07-9ea741d98521", n.type="d9202f0c-8737-46e7-9d07-9ea741d98521", n:_Vcaf, n:_Vira;
MERGE (n:Person{cdsid:"8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4"}) SET n.active="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.created="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.email="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.jobTitle="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.name="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.neo4jImportId="9801", n.officeLocation="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.synced="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.unifyAccess="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.unifyUser="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.viraActive="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4";
MERGE (n:Person{cdsid:"1fa11057-1f1d-433c-8246-73bd29137056"}) SET n.active="1fa11057-1f1d-433c-8246-73bd29137056", n.created="1fa11057-1f1d-433c-8246-73bd29137056", n.email="1fa11057-1f1d-433c-8246-73bd29137056", n.jobTitle="1fa11057-1f1d-433c-8246-73bd29137056", n.name="1fa11057-1f1d-433c-8246-73bd29137056", n.neo4jImportId="9814", n.officeLocation="1fa11057-1f1d-433c-8246-73bd29137056", n.synced="1fa11057-1f1d-433c-8246-73bd29137056", n.unifyAccess="1fa11057-1f1d-433c-8246-73bd29137056", n.unifyUser="1fa11057-1f1d-433c-8246-73bd29137056", n.viraActive="1fa11057-1f1d-433c-8246-73bd29137056";
MERGE (n:Person{cdsid:"96e6b89f-07a7-47e5-ba92-6581ea95a993"}) SET n.active="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.created="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.email="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.jobTitle="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.name="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.neo4jImportId="15295", n.officeLocation="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.synced="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.unifyAccess="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.unifyUser="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.viraActive="96e6b89f-07a7-47e5-ba92-6581ea95a993";
CREATE CONSTRAINT ON (node:Project) ASSERT (node.id) IS UNIQUE;
CREATE CONSTRAINT ON (node:Person) ASSERT (node.cdsid) IS UNIQUE;
CREATE CONSTRAINT ON (node:Team) ASSERT (node.id) IS UNIQUE;
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
MATCH (n1:Person{cdsid:"c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b"}), (n2:Team:`UNIQUE IMPORT LABEL`{id:"06455ff9-93dc-4ce2-b3a5-411983cb14ef", `UNIQUE IMPORT ID`:115}) MERGE (n1)-[r:LEADS]->(n2) SET r.`r&d_2.0`="bebfa4d9-fa60-4b74-b893-81bd2bf90193", r.synced="bebfa4d9-fa60-4b74-b893-81bd2bf90193";
MATCH (n1:Person{cdsid:"1f40a365-1843-487f-89f8-8fdd7addedf5"}), (n2:Team:`UNIQUE IMPORT LABEL`{id:"3709d610-46b1-46d0-9f10-b1ca0f492e8a", `UNIQUE IMPORT ID`:102}) MERGE (n1)-[r:IS_TEAM_MEMBER_OF]->(n2) SET r.created="69b81da9-58fe-4e7b-b8ef-87443d588e11", r.oldRole="69b81da9-58fe-4e7b-b8ef-87443d588e11", r.role="69b81da9-58fe-4e7b-b8ef-87443d588e11";
MATCH (n1:Person{cdsid:"8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4"}), (n2:Project:`UNIQUE IMPORT LABEL`{id:"d9202f0c-8737-46e7-9d07-9ea741d98521", `UNIQUE IMPORT ID`:117}) MERGE (n1)-[r:WORKS_FOR]->(n2) SET r.created="93f85bc2-3b0c-4e50-90c1-074e884998c5", r.teamId="93f85bc2-3b0c-4e50-90c1-074e884998c5", r.teamName="93f85bc2-3b0c-4e50-90c1-074e884998c5", r.teamRole="93f85bc2-3b0c-4e50-90c1-074e884998c5";
MATCH (n1:Person{cdsid:"1fa11057-1f1d-433c-8246-73bd29137056"}), (n2:Project:`UNIQUE IMPORT LABEL`{id:"d9202f0c-8737-46e7-9d07-9ea741d98521", `UNIQUE IMPORT ID`:117}) MERGE (n1)-[r:WORKS_FOR]->(n2) SET r.created="6e86b125-9f05-4457-96f7-6f71c5c70197", r.teamId="6e86b125-9f05-4457-96f7-6f71c5c70197", r.teamName="6e86b125-9f05-4457-96f7-6f71c5c70197", r.teamRole="6e86b125-9f05-4457-96f7-6f71c5c70197";
MATCH (n1:Person{cdsid:"96e6b89f-07a7-47e5-ba92-6581ea95a993"}), (n2:Team:`UNIQUE IMPORT LABEL`{id:"3376c40e-8fa3-4708-aa08-bef1783f40d1", `UNIQUE IMPORT ID`:113}) MERGE (n1)-[r:IS_TEAM_MEMBER_OF]->(n2) SET r.created="c8320475-486d-4afe-81cb-33d627212db2", r.oldRole="c8320475-486d-4afe-81cb-33d627212db2", r.role="c8320475-486d-4afe-81cb-33d627212db2";
MATCH (n:`UNIQUE IMPORT LABEL`)  WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
"

otherwise with apoc 3.5.0.12:

"MERGE (n:Person{cdsid:"1f40a365-1843-487f-89f8-8fdd7addedf5"}) SET n.active="1f40a365-1843-487f-89f8-8fdd7addedf5", n.created="1f40a365-1843-487f-89f8-8fdd7addedf5", n.email="1f40a365-1843-487f-89f8-8fdd7addedf5", n.jobTitle="1f40a365-1843-487f-89f8-8fdd7addedf5", n.name="1f40a365-1843-487f-89f8-8fdd7addedf5", n.neo4jImportId="5606", n.officeLocation="1f40a365-1843-487f-89f8-8fdd7addedf5", n.synced="1f40a365-1843-487f-89f8-8fdd7addedf5", n.unifyAccess="1f40a365-1843-487f-89f8-8fdd7addedf5", n.unifyUser="1f40a365-1843-487f-89f8-8fdd7addedf5", n.viraActive="1f40a365-1843-487f-89f8-8fdd7addedf5";
MERGE (n:Team{id:"3709d610-46b1-46d0-9f10-b1ca0f492e8a"}) SET n.name="3709d610-46b1-46d0-9f10-b1ca0f492e8a", n.neo4jImportId="6372829", n.synced="3709d610-46b1-46d0-9f10-b1ca0f492e8a", n:_Vira;
MERGE (n:Team{id:"3376c40e-8fa3-4708-aa08-bef1783f40d1"}) SET n.name="3376c40e-8fa3-4708-aa08-bef1783f40d1", n.neo4jImportId="9777303", n.synced="3376c40e-8fa3-4708-aa08-bef1783f40d1", n:_Vira;
MERGE (n:Person{cdsid:"c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b"}) SET n.active="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.created="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.email="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.jobTitle="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.name="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.neo4jImportId="15302", n.officeLocation="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.synced="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.unifyAccess="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.unifyUser="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b", n.viraActive="c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b";
MERGE (n:Team{id:"06455ff9-93dc-4ce2-b3a5-411983cb14ef"}) SET n.name="06455ff9-93dc-4ce2-b3a5-411983cb14ef", n.neo4jImportId="14474", n.`r&d_2.0`="06455ff9-93dc-4ce2-b3a5-411983cb14ef", n.synced="06455ff9-93dc-4ce2-b3a5-411983cb14ef", n:_Vira;
MERGE (n:Project{id:"d9202f0c-8737-46e7-9d07-9ea741d98521"}) SET n.artId="d9202f0c-8737-46e7-9d07-9ea741d98521", n.carWeaverName="d9202f0c-8737-46e7-9d07-9ea741d98521", n.carWeaverType="d9202f0c-8737-46e7-9d07-9ea741d98521", n.key="d9202f0c-8737-46e7-9d07-9ea741d98521", n.name="d9202f0c-8737-46e7-9d07-9ea741d98521", n.neo4jImportId="114933", n.`r&d_2.0`="d9202f0c-8737-46e7-9d07-9ea741d98521", n.streamPage="d9202f0c-8737-46e7-9d07-9ea741d98521", n.syncRequested="d9202f0c-8737-46e7-9d07-9ea741d98521", n.synced="d9202f0c-8737-46e7-9d07-9ea741d98521", n.type="d9202f0c-8737-46e7-9d07-9ea741d98521", n:_Vcaf, n:_Vira;
MERGE (n:Person{cdsid:"8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4"}) SET n.active="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.created="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.email="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.jobTitle="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.name="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.neo4jImportId="9801", n.officeLocation="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.synced="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.unifyAccess="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.unifyUser="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4", n.viraActive="8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4";
MERGE (n:Person{cdsid:"1fa11057-1f1d-433c-8246-73bd29137056"}) SET n.active="1fa11057-1f1d-433c-8246-73bd29137056", n.created="1fa11057-1f1d-433c-8246-73bd29137056", n.email="1fa11057-1f1d-433c-8246-73bd29137056", n.jobTitle="1fa11057-1f1d-433c-8246-73bd29137056", n.name="1fa11057-1f1d-433c-8246-73bd29137056", n.neo4jImportId="9814", n.officeLocation="1fa11057-1f1d-433c-8246-73bd29137056", n.synced="1fa11057-1f1d-433c-8246-73bd29137056", n.unifyAccess="1fa11057-1f1d-433c-8246-73bd29137056", n.unifyUser="1fa11057-1f1d-433c-8246-73bd29137056", n.viraActive="1fa11057-1f1d-433c-8246-73bd29137056";
MERGE (n:Person{cdsid:"96e6b89f-07a7-47e5-ba92-6581ea95a993"}) SET n.active="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.created="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.email="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.jobTitle="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.name="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.neo4jImportId="15295", n.officeLocation="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.synced="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.unifyAccess="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.unifyUser="96e6b89f-07a7-47e5-ba92-6581ea95a993", n.viraActive="96e6b89f-07a7-47e5-ba92-6581ea95a993";
CREATE CONSTRAINT ON (node:Project) ASSERT (node.id) IS UNIQUE;
CREATE CONSTRAINT ON (node:Person) ASSERT (node.cdsid) IS UNIQUE;
CREATE CONSTRAINT ON (node:Team) ASSERT (node.id) IS UNIQUE;
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
MATCH (n1:Person{cdsid:"c26c6f3d-ff5b-4fac-abea-d3ddaa7cdf9b"}), (n2:Team{id:"06455ff9-93dc-4ce2-b3a5-411983cb14ef"}) MERGE (n1)-[r:LEADS]->(n2) SET r.`r&d_2.0`="bebfa4d9-fa60-4b74-b893-81bd2bf90193", r.synced="bebfa4d9-fa60-4b74-b893-81bd2bf90193";
MATCH (n1:Person{cdsid:"1f40a365-1843-487f-89f8-8fdd7addedf5"}), (n2:Team{id:"3709d610-46b1-46d0-9f10-b1ca0f492e8a"}) MERGE (n1)-[r:IS_TEAM_MEMBER_OF]->(n2) SET r.created="69b81da9-58fe-4e7b-b8ef-87443d588e11", r.oldRole="69b81da9-58fe-4e7b-b8ef-87443d588e11", r.role="69b81da9-58fe-4e7b-b8ef-87443d588e11";
MATCH (n1:Person{cdsid:"8d7c0dcf-1df5-4f8c-abf4-8a7d98825bb4"}), (n2:Project{id:"d9202f0c-8737-46e7-9d07-9ea741d98521"}) MERGE (n1)-[r:WORKS_FOR]->(n2) SET r.created="93f85bc2-3b0c-4e50-90c1-074e884998c5", r.teamId="93f85bc2-3b0c-4e50-90c1-074e884998c5", r.teamName="93f85bc2-3b0c-4e50-90c1-074e884998c5", r.teamRole="93f85bc2-3b0c-4e50-90c1-074e884998c5";
MATCH (n1:Person{cdsid:"1fa11057-1f1d-433c-8246-73bd29137056"}), (n2:Project{id:"d9202f0c-8737-46e7-9d07-9ea741d98521"}) MERGE (n1)-[r:WORKS_FOR]->(n2) SET r.created="6e86b125-9f05-4457-96f7-6f71c5c70197", r.teamId="6e86b125-9f05-4457-96f7-6f71c5c70197", r.teamName="6e86b125-9f05-4457-96f7-6f71c5c70197", r.teamRole="6e86b125-9f05-4457-96f7-6f71c5c70197";
MATCH (n1:Person{cdsid:"96e6b89f-07a7-47e5-ba92-6581ea95a993"}), (n2:Team{id:"3376c40e-8fa3-4708-aa08-bef1783f40d1"}) MERGE (n1)-[r:IS_TEAM_MEMBER_OF]->(n2) SET r.created="c8320475-486d-4afe-81cb-33d627212db2", r.oldRole="c8320475-486d-4afe-81cb-33d627212db2", r.role="c8320475-486d-4afe-81cb-33d627212db2";
MATCH (n:`UNIQUE IMPORT LABEL`)  WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
"

so all MERGE statements leverage on unique constraint instead of UNIQUE IMPORT LABEL.

lovepreetkaur3395 commented 2 years ago

Hi @vga91 , The customer provided an update to the case that he has tested this against 3.5.0.15 and still having the same issue.

below is the cypher query that he ran:

CALL apoc.export.cypher.query("MATCH (p:Project)<-[r2]-(n:Person)-[r]->(m:Team) RETURN n,r,m,r2,p LIMIT 1","",
{useOptimizations: {type: "none"}, format: "plain", cypherFormat: "updateAll"})
YIELD cypherStatements RETURN cypherStatements

and here is the output :

MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:11178}) SET n.id="62367", n.name="ART ES WUKONG", n.`r&d_2.0`=false, n.synced="2021-09-04T00:02:45.156Z", n:Team, n:_Vira;
MERGE (n:Person{cdsid:"xxx"}) SET n.active=true, n.created="2019-01-01T00:00:00.000Z", n.email="xxx@volvocars.com", n.name="xxx", n.synced="2021-09-04T00:02:45.156Z", n.unifyAccess=264, n.unifyUser=true, n.viraActive=true;
MERGE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:5459139}) SET n.id="18903", n.artId="760", n.carWeaverName="ART Painted Body", n.key="ARTPB", n.name="ART Painted Body", n.`r&d_2.0`=true, n:Project, n:_Vcaf, n:_Vira;
CREATE INDEX ON :_Vira(id);
CREATE CONSTRAINT ON (node:Person) ASSERT (node.cdsid) IS UNIQUE;
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
MATCH (n1:Person{cdsid:"xxx"}), (n2:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:11178}) MERGE (n1)-[r:LEADS]->(n2) SET r.`r&d_2.0`=false, r.synced="2020-05-14T10:14:49.854Z";
MATCH (n1:Person{cdsid:"xxx"}), (n2:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:5459139}) MERGE (n1)-[r:WORKS_FOR]->(n2) SET r.created="2020-10-19T02:30:00.444Z", r.teamId="62433", r.teamName="ART PB Wukong";
MATCH (n:`UNIQUE IMPORT LABEL`) WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE

Can you please look into this and advise if we can replicate this at our end or we can go on a screensharing session with customer if that's possible for you?

vga91 commented 2 years ago

Done a screensharing session with the customer. The problem is no longer present (in 3.5.0.15 version)

msoni2505 commented 2 years ago

We are working with customer to upgrade their APOC version , will share and update when its done .