![](/img/trans.png)
[英]OrientDB ETL, create edge between two vertices which are already in Graph
[英]OrientDB create edge between two nodes with the same day of year
我有興趣在圖表中相同類別的兩個節點之間共享一條邊(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接口生成這些邊?
基於這個問題 ,我開始嘗試這樣的事情:
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組合在一起,但我現在寧願堅持使用盡可能多的SQL命令。
非常感謝您的幫助。
其他堆棧溢出參考
我嘗試使用OSQL批處理,但是我認為您無法獲得想要的東西。
使用WSQL 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
但是問題是,當您創建邊時,您無法在上一步獲得的表上循環。 我認為最好的解決方案是使用JS服務器端功能。 希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.