2017-12-18 41 views
0

我現在面臨的問題創造頂點,其中頂點之一是通過使用SQL定向功能越來越之間的邊緣,東方DB頂點誤差之間創建邊,頂點利用東方DB SQL函數

下面

閱讀是要求

讓我說我有3個頂點vertex1(@rid:#9:0),vertex2(@rid:#10:0),vertex3(@rid:#11:0)和邊緣beteween vertex1和頂點2已經存在。 現在我需要從vertex2獲得vertex1創造vertex1和vertex3之間的邊緣

Graph graph = new OrientGraph("remote:localhost:2424/test", "username", "password"); 
String query = "select @rid ad base, inE('child').outV() as source from V where name='vertex3'"; 

OrientGraph oGraph = (OrientGraph)graph; 
OCommandSQL oCommandSQL = new OCommandSQL(query); 
Iterable<Vertex> vertices = oGraph.command(oCommandSQL).execute(); 
Iterator<Vertex> verticesIterator = vertices.iterator(); 
Vertex resultVertex = verticesIterator.next(); 
OrientElementIterable<Element> elements = resultVertex.getProperty("source"); 
Iterator<Element> elementIterator = elements.iterator(); 
Vertex sourceVertex = null; 
while (elementIterator.hasNext()) { 
    sourceVertex = (Vertex) elementIterator.next(); 
} 
Vertex v3 = graph.getVertex("#11:0"); 
Edge edge = graph.addEdge(null, v3, sourceVertex, "new"); 
graph.shutdown(); 

例外:

java.lang.IllegalArgumentException異常:羣集段#-2不在數據庫中存在 「測試' 在com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.checkClusterSegmentIndexRange(OAbstractPaginatedStorage.java:4627) 在com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.getClusterById(OAbstractPaginatedStorage.java :3013)(ODbabaseDocumentTx.java: 3411) 在com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.executeReadRecord(ODatabaseDocumentTx.java:2022) 在com.orientechnologies.orient.core.tx.OTransactionOptimistic.loadRecord(OTransactionOptimistic.java:187) 在com.orientechnologies.orient.core.tx.OTransactionOptimistic.loadRecord(OTransactionOptimistic.java:162) 在com.orientechnologies.orient.core.tx.OTransactionOptimistic.loadRecord(OTransactionOptimistic.java:291) 在com.orientechnologies.orient。 core.db.document.ODatabaseDocumentTx .load(ODatabaseDocumentTx.java:1739) at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.load(ODatabaseDocumentTx.java:103) at com.orientechnologies.orient.core.id.ORecordId.getRecord(ORecordId .java:329) at com.orientechnologies.orient.server.tx.OTransactionOptimisticProxy.begin(OTransactionOptimisticProxy.java:176) at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.begin(ODatabaseDocumentTx.java:1881 ) at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.begin(ODatabaseDocumentTx.java:103) at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.commit(ONetworkProtocolBinary.java:1426 ) at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.exe cuteRequest(ONetworkProtocolBinary.java:668) at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.sessionRequest(ONetworkProtocolBinary.java:398) at com.orientechnologies.orient.server.network.protocol.binary。 ONetworkProtocolBinary.execute(ONetworkProtocolBinary.java:217) at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread。Java的:82)

+0

嗨,您使用的是哪個版本? –

+0

嗨,我正在使用orientdb-community-2.2.8 – user2982651

回答

1

最後我得到了我的代碼以UNWIND功能工作

String query = "select @rid ad base, inE('child').outV() as source from V where name='vertex3' UNWIND source"; 

我們還可以使用EXPAND功能

String query = "select @rid ad base, EXPAND(inE('child').outV()) as source from V where name='vertex3'"; 

但它會忽略多個投影

以下鏈接幫助我解決了這個問題

OrientDB SELECT and subqueries

https://github.com/orientechnologies/orientdb/issues/3755

http://orientdb.com/docs/last/SQL-Query.html#unwinding

謝謝

相關問題