New feature: Multi Collection Graphs
This version is deprecated. Download the new version of ArangoDB
With the 2.2 release we proudly announce that we now offer the feature of multi collection graphs. This allows you to group an arbitrary set of ArangoDB collections into one graph. In order to do this grouping you execute the following steps in arangosh or Foxx: 1. Require the general-graph module and create a graph.
var graph_module = require("org/arangodb/general-graph"); var graph = graph._create("myGraph");
- Add collections to be used as vertex collections. If the collections are not yet created, ArangoDB will create them for you.
graph._addVertexCollection("person"); graph._addVertexCollection("publication"); graph._addVertexCollection("university"); graph._addVertexCollection("company");
- Create edge definitions between your vertex collections. These definitions create edge collections and allow you to store edges where source and target vertices come from the collections written in the definition. If you give vertex collections unknown to the graph they will be added to the graph. You have two options to create such a definition, it is either undirected – the set of source and target vertex collections is identical:
graph._extendEdgeDefinitions(graph_module._undirectedRelation("friendship", "person")); graph._extendEdgeDefinitions(graph_module._undirectedRelation("has_cited", "publication"));
Or it is directed – the set of source and target vertex collections is different:
graph._extendEdgeDefinitions(graph_module._directedRelation("has_written", "person", "publication")); graph._extendEdgeDefinitions(graph_module._directedRelation("has_worked_for", "person", ["company", "university"]));
Using this graph module now gives you the following benefits:
No loose ends: If you delete a vertex in the graph, all connected edges of all graphs are removed as well. Everything transactional: All operations within the graph module are transactional. Use graphs in AQL: All graph functions (neighbors, shortest path, traversal, etc.) are easily available in AQL. For instance, you can filter your starting vertices using standard AQL and then do a traversal given your graph name and these vertices in one AQL call. Overlapping Graphs: You can add the same edge definition to several graphs. This allows you to define several “views” of your data. To give you an example:
var academical = graph._create("academical"); academical._extendEdgeDefinitions(graph_module._undirectedRelation("friendship", "person")); academical._extendEdgeDefinitions(graph_module._directedRelation("has_written", "person", "publication")); var business = graph._create("business"); business._extendEdgeDefinitions(graph_module._undirectedRelation("friendship", "person")); business._extendEdgeDefinitions(graph_module._directedRelation("has_worked_for", "person", ["company", "university"]));
Now you have two graphs sharing friendship.
Fluent Query Interface: There is a fluent interface to generate and handle AQL queries. You start by selecting a subset of your graph (edges or vertices) and from there on explore the graph. To give you an example suppose you want to query all papers that have been influenced directly or indirectly by publications of Amazon. 1. You start by selecting the company Amazon.
var query = graph._vertices({name: "Amazon"}).restrict("company")
- Next you find all the papers that have been published by employees of the company (two hop neighbors).
query = query.neighbors({}, {minDepth: 2, maxDepth: 2}).restrict("publication")
- Select all papers reachable in a path using only inbound “has_cited” edges (1-n hop inbound neighbors)
query = query.neighbors({}, {maxDepth: Infinity, direction: "inbound", edgeCollectionRestriction: "has_cited"})
- Finally print the result:
query.toArray()
This generates the following AQL:
FOR vertices_0 IN GRAPH_VERTICES("myGraph", {name: "Amazon"}, "vertexCollectionRestriction": ["company"]) FOR neighbors_1 IN GRAPH_NEIGHBORS("myGraph", vertices_0, {"minDepth": 2,"maxDepth": 2,"neighborExamples": {}, "vertexCollectionRestriction": ["publication"]}) FOR neighbors_2 IN GRAPH_NEIGHBORS("myGraph", neighbors_1.vertex, "maxDepth": Infinity, "direction": "inbound", "edgeCollectionRestriction": "e", "neighborExamples": {}) RETURN neighbors_2.vertex
For further information have a look
in our documentation. 5. REST API: Also the functionality to manage the graphs is offered via the endpoint
_api/gharial
for it’s features please have a look
<a href="http://docs.arangodb.com/HttpGharial/index.html" title="HTTP Graph Documentation" target="_blank">at our documentation</a>.
6. Web Interface: Manage your graphs in the interface and view them using the graph viewer. Some words on
backwards compatibility: If you already have created a graph using the old graph module this graph will be transformed into the new layout during the upgrade procedure. The old module is still available and works as before. In addition the graph can be accessed using the new module. For our API implementors, there are some differences in the HTTP API in addition to the different endpoint: * Creation of graphs now expects different parameters, one vertex and one edge collection are not enough. * Creation of vertices now expect a POST to {graphname}/vertex/{collectionname} as we cannot figure out where to store the vertex otherwise. * Same for creation of edges. * Measurements are no longer offered by the API, they have been included in AQL
2 Comments
Leave a Comment
Get the latest tutorials, blog posts and news:
Can I show 2 different graphs in one graph viewer?
yes u can do it…..in one graph u can create two sub-graphs