问题描述
如果它们共享一年中的同一天并且 v.year = u.year+1,我想在图中同一类的两个节点之间创建边 (u,v).
假设我有 vertices.csv:
id,日期一、2014-01-02乙,2015-01-02C,2016-01-02D,2013-06-01E,2014-06-01F,2016-06-01
我想看到的边缘结构是这样的:
A -->B -->CD-->乙F
让我们将顶点类设置为myVertex",将边类设置为myEdge"?是否可以使用 SQL 接口生成这些边?
基于
使用 whis OSQL 批处理
开始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))犯罪返回 $a
我得到了这个
但问题是,当您创建边时,您无法在上一步获得的表上循环.我认为最好的解决方案是使用 JS 服务器端功能.希望有帮助.
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
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.
这篇关于OrientDB 在同一年的同一天在两个节点之间创建边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!