如何检索 Pregel ArangoDB 的结果?
How to retrieve the result of Pregel ArangoDB?
我是新手,使用的是 ArangoDB 3.2.5。我想在 ArangoDB 中检索预凝胶的结果。这是 arangosh 中的一个简单示例。
var pregel = require("@arangodb/pregel");
var params = {source: "Country/Tunesia"};
var execution = pregel.start("sssp", "CountryGraph", params);
文档中,将pregel的结果转储到集合的一个字段中。是否有像以下代码这样的替代方法来检索结果?我在文档中查找它但没有找到它。对了,你可以通过加载this来加载上面代码使用的数据集示例。谢谢
var result = pregel.getResult(execution);
无法直接返回结果。但是,您有两个选择:
- 让ArangoDB将Pregel结果写入文档
- 不存储结果,只是暂时保存在内存中
为了避免持久化结果,有一个option store
which you have to set to false.
You can access the volatile result with AQL通过函数PREGEL_RESULT(<handle>)
。
流程是这样的:
- 开始执行 Pregel
- 检查状态并等待状态变为 "done" 或 "canceled"
- 如果 Pregel 成功,则执行 AQL 查询以访问结果
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
}
]
我是新手,使用的是 ArangoDB 3.2.5。我想在 ArangoDB 中检索预凝胶的结果。这是 arangosh 中的一个简单示例。
var pregel = require("@arangodb/pregel");
var params = {source: "Country/Tunesia"};
var execution = pregel.start("sssp", "CountryGraph", params);
文档中,将pregel的结果转储到集合的一个字段中。是否有像以下代码这样的替代方法来检索结果?我在文档中查找它但没有找到它。对了,你可以通过加载this来加载上面代码使用的数据集示例。谢谢
var result = pregel.getResult(execution);
无法直接返回结果。但是,您有两个选择:
- 让ArangoDB将Pregel结果写入文档
- 不存储结果,只是暂时保存在内存中
为了避免持久化结果,有一个option store
which you have to set to false.
You can access the volatile result with AQL通过函数PREGEL_RESULT(<handle>)
。
流程是这样的:
- 开始执行 Pregel
- 检查状态并等待状态变为 "done" 或 "canceled"
- 如果 Pregel 成功,则执行 AQL 查询以访问结果
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
}
]