OrientDB - LET变量在哪里

时间:2015-05-12 15:19:59

标签: where orientdb let

我的查询非常类似于此:

SELECT FROM Post 
LET 
$category = (SELECT EXPAND(out('PartOf')) FROM $current),
$poster = (SELECT EXPAND(in('Posted')) FROM $current) 
WHERE 
$poster <> #18:1
AND $poster IN (SELECT EXPAND(out('IsUser')) FROM (SELECT EXPAND(out('Related')) FROM #18:1) WHERE out('RelatedIn') IN ($category))
LIMIT 10000

这样的图表:

CREATE CLASS Post EXTENDS V;
CREATE CLASS Category EXTENDS V;
CREATE CLASS User EXTENDS V;
CREATE CLASS UserRelated EXTENDS V;
CREATE CLASS PartOf EXTENDS E;
CREATE CLASS IsUser EXTENDS E;
CREATE CLASS Posted EXTENDS E;
CREATE CLASS Related EXTENDS E;
CREATE CLASS RelatedIn EXTENDS E;

PartOf relates Post and Cateogry
IsUser relates UserRelated and User
Posted relates User and Post
Related relates User and UserRelated
RelatedIn relates UserRelated and Category

UserRelated is an hyper-edge

我正在寻找的是来自与其他用户相关的用户的帖子(#18:1),其中用户之间的关系与该时刻查询所经过的帖子的类别属于同一类别。

AND之后的where子句不起作用。如果我删除它,查询会给出相同的结果。

另一方面,如果我使用特定的@rid更改该子句中的$ category,则查询工作正常...但我需要多个特定类别。

那么,这个查询有什么问题?

(我希望这个解释很清楚)

由于

1 个答案:

答案 0 :(得分:1)

似乎无法从哪里访问$ category。我真的不知道为什么。 但是我用另一个变量解决了它:

SELECT FROM Post 
LET 
$category = (SELECT EXPAND(out('PartOf')) FROM $current),
$poster = (SELECT EXPAND(in('Posted')) FROM $current),
$relatedUser = (SELECT EXPAND(out('IsUser')) FROM (SELECT EXPAND(out('Related')) FROM #18:1) WHERE out('RelatedIn') IN ($parent.category))
WHERE 
$poster <> #18:1
AND $poster IN ($relatedUser)
LIMIT 10000

关键是在子查询中使用$ parent.category。我不太清楚父类中的声明变量应该与任何子查询中的$ parent.variable一起使用。

我希望这有助于将来的某个人!