tianxiang xia
tianxiang xia

Reputation: 3

How to retrieve the result of Pregel ArangoDB?

I am a newbie and using ArangoDB 3.2.5. I would like to retrieve the result of pregel in ArangoDB. Here is a simple example in arangosh.

var pregel = require("@arangodb/pregel");
var params = {source: "Country/Tunesia"};
var execution = pregel.start("sssp", "CountryGraph", params);

In the document, it dumps the result of pregel in a field in the collection. Is there an alternative way like the following code to retrieve the result? I look for it in the document but didn't find it. By the way, you can load the dataset example used by the above code by loading this. Thanks.

var result = pregel.getResult(execution);

Upvotes: 0

Views: 532

Answers (1)

CodeManX
CodeManX

Reputation: 11885

The result can not be returned directly. You have two options however:

  • Let ArangoDB write the Pregel result into the documents
  • Don't store the result, but only hold it temporarily in memory

To avoid persisting the result, there is an option store which you have to set to false. You can access the volatile result with AQL through the function PREGEL_RESULT(<handle>).

The flow is like this:

  1. Start Pregel execution
  2. Check status and wait until it changes to "done" or "canceled"
  3. Perform an AQL query to access the result if Pregel succeeded
var pregel = require("@arangodb/pregel");
var params = {source: "Country/Algeria", store: false};
var handle = pregel.start("sssp", "CountryGraph", params);

while (!["done", "canceled"].includes(pregel.status(handle).state)) {
  print("waiting for result");
  require("internal").wait(0.5); // TODO: make this more clever
}

var status = pregel.status(handle);
print(status);

if (status.state == "done") {
  var query = db._query("FOR doc IN PREGEL_RESULT(@handle) RETURN doc", {handle: handle});
  print(query.toArray());
}

The output looks like this:

shell>arangosh --javascript.execute pregel.js

waiting for result

{
  "state" : "done",
  "gss" : 2,
  "totalRuntime" : 0.00583648681640625,
  "aggregators" : {
  },
  "sendCount" : 1,
  "receivedCount" : 1,
  "vertexCount" : 10,
  "edgeCount" : 8,
  "code" : 200
}

[
  {
    "_key" : "Germany",
    "result" : 9223372036854776000
  },
  {
    "_key" : "Switzerland",
    "result" : 9223372036854776000
  },
  {
    "_key" : "Brasil",
    "result" : 9223372036854776000
  },
  {
    "_key" : "Marocco",
    "result" : 9223372036854776000
  },
  {
    "_key" : "Argentina",
    "result" : 9223372036854776000
  },
  {
    "_key" : "Austria",
    "result" : 9223372036854776000
  },
  {
    "_key" : "Algeria",
    "result" : 0
  },
  {
    "_key" : "Uruguay",
    "result" : 9223372036854776000
  },
  {
    "_key" : "Tunesia",
    "result" : 1
  },
  {
    "_key" : "Australia",
    "result" : 9223372036854776000
  }
]

Upvotes: 1

Related Questions