OrientDB 在一年中同一天的两个节点之间创建边

OrientDB create edge between two nodes with the same day of year

我有兴趣在图中相同 class 的两个节点之间创建一条边 (u,v),如果它们共享一年中的同一天并且 v.year = u.year+1.

假设我有 vertices.csv:

id,date
A,2014-01-02
B,2015-01-02
C,2016-01-02
D,2013-06-01
E,2014-06-01
F,2016-06-01

我希望看到的边缘结构是这样的:

A --> B --> C
D --> E
F

让我们将顶点 class 设置为 "myVertex",将边 class 设置为 "myEdge"?是否可以使用 SQL 接口生成这些边?

基于,我开始尝试这样的事情:

BEGIN
LET source = SELECT FROM myVertex
LET target = SELECT from myVertex
LET edge   = CREATE EDGE myEdge
             FROM $source
             TO (SELECT FROM $target WHERE $source.date.format('MM-dd') = $target.date.format('MM-dd')
                 AND $source.date.format('yyyy').asInteger() = $target.date.format('yyyy').asInteger()-1)
COMMIT

不幸的是,这是不正确的。所以我没有那么雄心勃勃,想看看我是否可以仅根据匹配的年份来创建边缘:

BEGIN
LET source = SELECT FROM myVertex
LET target = SELECT from myVertex
LET edge   = CREATE EDGE myEdge FROM $source TO (SELECT FROM $target WHERE $source.date.format('MM-dd') = $target.date.format('MM-dd'))
COMMIT

仍然有错误...我相信对于有经验的 OrientDB 用户来说这很简单。

我考虑过将 JavaScript 功能组合在一起,例如 Michela suggested on this question,但我现在宁愿尽可能多地坚持使用 SQL 命令。

非常感谢帮助。


其他 Stack Overflow 参考资料

我试过使用 OSQL 批处理,但我认为你得不到你想要的。

使用 whis OSQL 批处理

begin
let a = select @rid, $a1 as toAdd from test let $a1 = (select from test where date.format("MM") == $parent.$current.date.format("MM") and date.format("dd") == $parent.$current.date.format("dd") and @rid<>$parent.$current.@rid and date.format("yyyy") == sum($parent.$current.date.format("yyyy").asInteger(),1))
commit
return $a

我知道了

但问题是,当你创建边缘时,你不能在上一步获得的 table 上循环。 我认为最好的解决方案是使用 JS 服务器端函数。 希望对你有帮助。