Skip to content
Luke Bakken edited this page Oct 5, 2016 · 2 revisions

Exporting to an Erlang digraph

Contributed By: Ryan Maclear

Source File on GitHub

This Erlang module allows you to construct an Erlang digraph from objects in a bucket. Each object will result in a vertex being created, identified by the key, and optionally, the object value will be used for the vertex label. Links on objects will result in edges being created as specified by each link. An optional filter list can be specified which will result in only specific objects matching the filter being used to construct the digraph. If the filter list is omitted, the entire bucket will be used.

This function can be used to recreate digraphs stored in a bucket using Digraph Importer found elsewhere on this site.

Notes

The function uses the Erlang Protocol Buffer client, so the correct ip address and port must be specified.

The digraph needs to be passed into the function, so it needs to exist and have the correct properties (eg. [cyclic, protected]).

Since digraphs are created in ETS, there is a finite limit on the number of vertices and edges that can be created, so be sure that you use filter lists where necessary.

Unfortunately, edges cannot be added to digraphs unless both vertices exist, so all the vertices are created first, and then only are the edges added. This means that the list of objects is traversed twice, and might have an impact on performance. Edges that cannot be created due to one or both vertices missing will be ignored.

The content-type of the object is used when creating the digraph label. If the content-type is application/x-erlang-binary, the label will be an erlang term, otherwise it will be a string (list).

Setting the last parameter of the function to false will result in all vetices having a label of [].

Examples

(Note: The cluster used for the example below is the dev cluster used in the Fast Track, so the port number used is 8082, and not the default port of 8087).

To create a digraph from an entire bucket, using the object values for the label:

A = digraph:new([cyclic, protected]).                                     
 
digraph_exporter:export_digraph("127.0.0.1", 8082, <<"networks">>, A, true).

To create a digraph from an entire bucket, with vetex labels:

A = digraph:new([cyclic, protected]).                                     
 
digraph_exporter:export_digraph("127.0.0.1", 8082, <<"networks">>, A, false).

To create a digraph from a bucket, using only objects with keys starting with home, using the object values for the label:

 A= digraph:new([cyclic, protected]).                                     
 
 digraph_exporter:export_digraph("127.0.0.1", 8082, <<"networks">>, [<<"starts_with">>,<<"home">>], A, true).