Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-05-2020 05:52 AM
Hello team,
Need your help for below ask:
Neo4j version - 3.5.3
I have 2 labels named as 'XYZ' and 'ABC' respectively and having properties with same name under them.
I want to know the difference of data between them and for which property ( assuming there is a difference in data ).
Best Regards
A
02-05-2020 08:30 AM
Can you clarify what you mean by "difference of data between them and for which property"? do you need to compare every pair of XYZ and ABC nodes or is there a property that can be used to match an ABC node with a XYZ node and then compare?
02-05-2020 09:06 AM
Hello Shan,
Let me share more details with you:-
I am loading Serial Number ( Unique Value ) , devicetype , model from csv eveyday to a label ABC. Lets assume on day 1 , Total count of records in label ABC is 20.
Now on Day 2, I am loading the same parameters Serial Number ( Unique Value ) , devicetype , model from csv eveyday to a label XYZ ( values may or may not same present under label ABC ) , Total count of records in label ABC is 30.
Now I need to know what are the common values between 2 labels ABC & XYZ assuming Serial Number property is the unique property in both labels?
I need this difference as there are chances that on Day 2 , Some of the serial numbers will not be available which was earlier present on DAY 1.
Regards
Akshat
02-05-2020 12:24 PM
You can do something like this:
MATCH (a:ABC)
OPTIONAL MATCH (b:XYZ) WHERE a.serialNum=b.serialNum
WITH COLLECT({serialNum: a.serialNum, before:a, after:b}) AS res1
WITH [x IN res1 WHERE x.after IS NOT null | x.serialNum] AS includedXYZs, res1
MATCH (b:XYZ) WHERE NOT b.serialNum in includedXYZs
WITH res1 + COLLECT({serialNum: b.serialNum, before:null, after:b}) AS res
RETURN res
res
will have those that either appear in both ABC and XYZ or just ABC. I used before
and after
to save the node props for ABC and XYZ respectively. Then I will add to res1
, those XYZ nodes that do not have a peer ABC node and return the final result as res
.
02-06-2020 04:36 AM
Hello Shan,
Thanks a lot for helping me.
Using your query , I got the result but i am interested only in Serial Number which got deleted or not present in 2nd day data.
Best Regards
Akshat
02-06-2020 04:48 AM
Below is my query which i replicated using your query:
MATCH (a:DAY1)
OPTIONAL MATCH (b:DAY2)
WHERE a.CIRCUIT_ID=b.CIRCUIT_ID
WITH COLLECT({CIRCUIT_ID: a.CIRCUIT_ID, before:a, after:b}) AS res1
WITH [x IN res1 WHERE x.after IS NOT null | x.CIRCUIT_ID] AS includedXYZs, res1
MATCH (b:DAY2) WHERE NOT b.CIRCUIT_ID in includedXYZs
WITH res1 + COLLECT({CIRCUIT_ID: b.CIRCUIT_ID, before:null, after:b}) AS res
RETURN res
Output of the query:
{
"before": {
"CUSTOMER_ID": "9000180919",
"STATUS": "IN SERVICE",
"NEID": "INAPABJPXXXXTW6004ENBESR001",
"CIRCUIT_ID": "L3VPN_M_9000180919_900100000004_299355693011"
},
"CIRCUIT_ID": "L3VPN_M_9000180919_900100000004_299355693011",
"after": {
"CUSTOMER_ID": "9000180919",
"STATUS": "IN SERVICE",
"NEID": "INAPABJPXXXXTW6004ENBESR001",
"CIRCUIT_ID": "L3VPN_M_9000180919_900100000004_299355693011"
}
}
,============================================
{
"before": {
"CUSTOMER_ID": "9000111256",
"STATUS": "IN SERVICE",
"NEID": "INAPADNKADNKTW6002ENBESR001",
"CIRCUIT_ID": "L3VPN_M_9000111256_901400000012_299351118566"
},
"CIRCUIT_ID": "L3VPN_M_9000111256_901400000012_299351118566",
"after": null
}
,
{
"before": {
"CUSTOMER_ID": "9185360012",
"STATUS": "COMMISSIONED",
"NEID": "INAPAGRIXXXXTW0001ENBESR001",
"CIRCUIT_ID": "ILL_9185360012_299357344768"
},
"CIRCUIT_ID": "ILL_9185360012_299357344768",
"after": {
"CUSTOMER_ID": "9185360012",
"STATUS": "COMMISSIONED",
"NEID": "INAPAGRIXXXXTW0001ENBESR001",
"CIRCUIT_ID": "ILL_9185360012_299357344768"
}
}
,
{
"before": null,
"CIRCUIT_ID": "L3VPN_H_9000111256_901400000012_299351118566",
"after": {
"CUSTOMER_ID": "9000111256",
"STATUS": "IN SERVICE",
"NEID": "INAPADNKADNKTW6002ENBESR001",
"CIRCUIT_ID": "L3VPN_H_9000111256_901400000012_299351118566"
}
}
======= Expected Output=======
L3VPN_M_9000111256_901400000012_299351118566 { As this is the circuit id which not loaded in day2 label when compared to label day1.
Regards
Akshat
02-06-2020 11:02 AM
oh that's a lot easier. Here are 2 alternatives:
MATCH (a:Day1)
OPTIONAL MATCH (b:Day2) where a.CIRCUIT_ID=b.CIRCUIT_ID
WITH a WHERE b IS null
RETURN a
or
MATCH (b:DAY2) WITH collect(b.CIRCUIT_ID) AS day2s
MATCH (a:DAY1) WHERE NOT a.CIRCUIT_ID IN day2s
RETURN a
02-06-2020 10:10 PM
Hello Shan,
Amazing Work Shan!!!
I got the expected result.
Many Thanks !!
Best Regards
Akshat
All the sessions of the conference are now available online