Orientdb size()从IF()内部返回不同的结果

时间:2018-05-14 17:54:04

标签: methods conditional orientdb

此示例使用Tolkien-Arda示例数据库和批处理模式。以下脚本

LET $1 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='hildigrimTook';
LET $2 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='adalgrimTook';
SELECT INTERSECT($1, $2).size();

返回7(我添加了额外内容,我认为默认值为2)

但是,当在完整脚本中使用时,size()似乎返回0,因此它总是创建一个新边

LET $1 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='hildigrimTook';
LET $2 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='adalgrimTook';
LET $3 = SELECT INTERSECT($1, $2);
LET $4 = CREATE EDGE Begets FROM (SELECT FROM Creature WHERE uniquename='hildigrimTook') TO (SELECT FROM Creature WHERE uniquename='adalgrimTook');
IF($3.size() > 0) {
    return 'Already present';
}
IF($3.size() == 0) {
    return $4;
}

此脚本应检查hildigrimTook和adalgrimTook之间的边缘,如果它尚不存在则创建边缘。似乎INTERSECT($ 1,$ 2).size()在从IF()语句内部调用时返回0,但在用作SELECT的一部分时返回7.

我试过了

LET $1 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='hildigrimTook';
LET $2 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='adalgrimTook';
LET $3 = SELECT INTERSECT($1, $2);
SELECT $3.size()

但这也回归0.我也做了

LET $1 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='hildigrimTook';
LET $2 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='adalgrimTook';
LET $3 = SELECT INTERSECT($1, $2).size();
SELECT $3;

按预期返回7但是当我尝试在IF语句中运行它时,我得到一个Java空指针异常

IF($3 > 0) {
    return 'Already present';
}
IF($3 == 0) {
    return $4;
}

预期的输出将是脚本返回“已经存在”或新创建的边缘的@rid。帮助赞赏,我已经尝试了我能想到的每一种方式,文档中没有详细介绍IF。

0 个答案:

没有答案