2016-09-14 51 views
0

我有興趣在圖形中的同一類的兩個節點之間創建邊(u,v),如果它們共享一年的同一天和v.year = u.year + 1。OrientDB創建兩個節點之間的邊緣,每年的同一天

說我有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命令。

非常感謝幫助。


其他堆棧溢出參考

+0

使用JS服務器端功能會更容易。讓我知道你是否想得到一些幫助。 –

+0

@ oleksandr-gubchenko我正在研究這個服務器端函數...是否有一些良好的文檔與創建/使用函數的例子鏈接?我已經完成了大量的Javascript編碼已經有幾年了......如果我用'V [i] .getRecord()。field('date')'在腳本中記錄一個日期,那會不會只是返回一個[javascript日期對象](http://www.w3schools.com/jsref/jsref_obj_date.asp)? 現在我可以在Studio中運行,但是我可能想要了解如何通過某個控制檯界面在數據庫中添加和使用它們。 – TxAG98

+0

有關Javascript API的官方文檔:http:// orientdb。com/docs/last/Javascript-Driver.html –

回答

2

我OSQL一批嘗試,但我認爲你不能得到你想要的東西。

enter code here

隨着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<>[email protected] and date.format("yyyy") == sum($parent.$current.date.format("yyyy").asInteger(),1)) 
commit 
return $a 

我得到這個 enter image description here

但問題是,當你創建的邊緣,你可以在前面獲得的表不循環步。 我認爲最好的解決方案是使用JS服務器端功能。 希望它有幫助。

+0

我可以做一個服務器端功能,但我可能無法在所有環境中運行服務器。我正在研究Java代碼,通過查詢來獲得邊緣對的表格,然後我將分別進行創建邊緣。這個例子雖然幫助了很多,但是我之前沒有用sum()函數和asInteger()方法進行實驗。我添加了一個較少的雄心勃勃的問題集中在[日期操作在OSQL](http://stackoverflow.com/questions/39713423/orientdb-date-manipulation-in-osql-to-find-a-path-with-nodes-在最當日,但是)。這幫助了很多。謝謝! – TxAG98

相關問題