I have two Graphs and I wanted to compare the difference between them. As a result from the AQL query I want only the difference in path and vertices between them. Is there any query in ArangoDb for it. Please let me know if its possible. Thanks in advance.
Asked
Active
Viewed 242 times
2 Answers
2
As first, you would execute both in a subquery:
LET queryA = (RETURN {myFirstGraphResult: true, a: true, b: true})
LET queryB = (RETURN {mySecondGraphResult: true, a: true, b: true})
RETURN queryA == queryB
Replace the two first RETURN
s with your actual query. You need to make shure they're in the same sequence, so if you have an array in it with several paths, SORT
it first.
If you want to know the actual differences between the two paths, Jan has created a nice blogpost howto get the differences of two documnets in AQL

dothebart
- 5,972
- 16
- 40
-
I tried this method and even if the graph is same it gives the result false. – Haseb Ansari Feb 04 '16 at 08:41
-
I tried this method and even if the graph is same it gives the result false. I wrote the example in below answer pls have a look at it. – Haseb Ansari Feb 04 '16 at 08:55
0
{
"graph1": [
{
"vertices": [
{
"task": "A",
"_id": "ExampleCollection/A",
"_rev": "184076271151",
"_key": "A"
},
{
"task": "B",
"_id": "ExampleCollection/B",
"_rev": "184078695983",
"_key": "B"
}
],
"edges": [
{
"relation": "A to B",
"_id": "ExampleEdges/184091213359",
"_rev": "184247516719",
"_key": "184091213359",
"_from": "ExampleCollection/A",
"_to": "ExampleCollection/B"
}
]
},
{
"vertices": [
{
"task": "A",
"_id": "ExampleCollection/A",
"_rev": "184076271151",
"_key": "A"
},
{
"task": "C",
"_id": "ExampleCollection/C",
"_rev": "184081120815",
"_key": "C"
}
],
"edges": [
{
"relation": "A to C",
"_id": "ExampleEdges/184250269231",
"_rev": "184251711023",
"_key": "184250269231",
"_from": "ExampleCollection/A",
"_to": "ExampleCollection/C"
}
]
}
],
"graph2": [
{
"vertices": [
{
"task": "A",
"_id": "ExampleCollection/184258199087",
"_rev": "184262917679",
"_key": "184258199087"
},
{
"task": "R",
"_id": "ExampleCollection/R",
"_rev": "184084397615",
"_key": "R"
}
],
"edges": [
{
"relation": "A to R",
"_id": "ExampleEdges/184265145903",
"_rev": "184270781999",
"_key": "184265145903",
"_from": "ExampleCollection/184258199087",
"_to": "ExampleCollection/R"
}
]
},
{
"vertices": [
{
"task": "A",
"_id": "ExampleCollection/184258199087",
"_rev": "184262917679",
"_key": "184258199087"
},
{
"task": "Q",
"_id": "ExampleCollection/Q",
"_rev": "184082365999",
"_key": "Q"
}
],
"edges": [
{
"relation": "A to Q",
"_id": "ExampleEdges/184264883759",
"_rev": "184272420399",
"_key": "184264883759",
"_from": "ExampleCollection/184258199087",
"_to": "ExampleCollection/Q"
}
]
}
]
}
Like in this case it gives me false result though the pattern is same.
@dothebart

Haseb Ansari
- 587
- 1
- 7
- 23
-
its completely right, they're different. have a look at `graph1[0].vertices[0]._id` vs. `graph2[0].vertices[0]._id` - `ExampleCollection/A` vs. `ExampleCollection/184258199087`. If you only want to compare `task`, you should create a query that only returns them instead of the whole edge. Else it can't say same if its only somewhat similar. – dothebart Feb 04 '16 at 09:22
-
though my task name is different its showing true while comparing when I return variable.task – Haseb Ansari Feb 04 '16 at 18:16
-
-
@dothebart , just another observation, two graphs with exactly the same structure (A->B->C) but only difference is the document handle for every node is different. Comparison of such two graphs is still giving false when compared. As i understand the Document handle is also being compared for every node and the handle will always be different . So the core graph structure will never be compared to be equal. – Haseb Ansari Feb 08 '16 at 10:48
-
The sequence of the documents and the documents themselves have to be equal to get a `True`. You have to assure that by extracting compareable bits of the complete documents, and sort them. Else you will have to compare the graphs using a [user defined function](https://docs.arangodb.com/AqlExtending/index.html), or outside of AQL using FOXX service, or outside of ArangoDB in your application. – dothebart Feb 08 '16 at 11:38