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

淺唱寂寞╮ 提交于 2019-12-12 04:24:41

问题


I'm interested in creating an edge (u,v) between two nodes of the same class in a graph if they share the same day of year and v.year = u.year+1.

Say I have 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

The edge structure I'd like to see would be this:

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

Let's set the vertex class to be "myVertex" and edge class to be "myEdge"? Is it possible to generate these edges using the SQL interface?

Based on this question, I started trying something like this:

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

Unfortunately, this isn't correct. So I got less ambitious and wanted to see if I can create edges just based on matching day-of-year:

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

Which still has errors... I'm sure it's something pretty simple to an experienced OrientDB user.

I thought about putting together a JavaScript function like Michela suggested on this question, but I'd prefer to stick to using the SQL commands as much as possible for now.

Help is greatly appreciated.


Other Stack Overflow References

  • How to print or log on function javascript OrientDB

回答1:


I tried with OSQL batch but I think that you can't get what you want.

With whis OSQL batch

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

I got this

but the problem is that when you create the edge you can not cycle on the table obtained in the previous step. I think the best solution is to use an JS server-side function. Hope it helps.



来源:https://stackoverflow.com/questions/39500535/orientdb-create-edge-between-two-nodes-with-the-same-day-of-year

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!