如何检索Pregel ArangoDB的结果?

时间:2018-01-10 07:02:08

标签: arangodb

我是新手并使用ArangoDB 3.2.5。我想在ArangoDB中检索pregel的结果。这是一个简单的例子。

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

在文档中,它将pregel的结果转储到集合中的字段中。有没有像下面的代码一样的替代方法来检索结果?我在文档中查找它但没找到它。顺便说一句,您可以通过加载this来加载上述代码使用的数据集示例。感谢。

var result = pregel.getResult(execution);

1 个答案:

答案 0 :(得分:0)

结果无法直接返回。但是你有两个选择:

  • 让ArangoDB将Pregel结果写入文档
  • 不要存储结果,只能暂时将其保存在内存中

为避免持久存在结果,您必须将option store设置为false.您可以access the volatile result with AQL通过函数PREGEL_RESULT(<handle>)

流程是这样的:

  1. 启动Pregel执行
  2. 检查状态并等到它变为&#34;完成&#34;或&#34;取消&#34;
  3. 如果Pregel成功,则执行AQL查询以访问结果
  4. 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());
    }
    

    输出如下:

    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
      }
    ]