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

时间:2016-09-14 22:21:07

标签: orientdb

我有兴趣在图表中同一个类的两个节点之间创建一个边(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

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

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

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用户来说这是非常简单的事情。

我考虑过将像Michela suggested on this question这样的JavaScript函数放在一起,但我现在更愿意尽可能多地使用SQL命令。

非常感谢帮助。

其他Stack Overflow References

1 个答案:

答案 0 :(得分:2)

我尝试使用OSQL批处理,但我认为你无法得到你想要的东西。

enter code here

使用whisker 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
我得到了这个 enter image description here

但问题是,当您创建边缘时,无法在上一步中获得的表格上循环。 我认为最好的解决方案是使用JS服务器端功能。 希望它有所帮助。

相关问题