东方DB在顶点错误之间创建边缘,通过使用Orient DB SQL函数读取顶点



我正在面临一个问题,以在顶点之间创建边缘,其中一个顶点通过使用oritient sql函数获得了一个问题,

以下是要求

说我有3个顶点vertex1(@rid:#9:0),vertex2(@rid:#10:0),vertex3(@rid:#11:0),而edge boteween tereween vertex1和dertex 2 is已经存在。现在,我需要从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.oabstractpaginedstorage.CheckClusterSegentEndExrange(oabstractPaginedStorage.java:4627) 在com.orientechnologies.orient.core.storage.impl.local.oabstractpaginedstorage.getClusterbyId(oabstractPaginedStorage.java:3013) 在com.orientechnologies.orient.core.storage.impl.local.oabstractpaginedstorage.ReadRecord(oabstractpaginedstorage.java:1404) 在com.orientechnologies.orient.core.db.document.odatabasedocumenttx $ simpleerecordreader.readrecord(odatabasedocumenttx.java:3411)) at 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) at com.orientechnologies.orient.core.tx.otransactionoptimistic.loadrecord(otransactionOptimistic.java:291) at com.orientechnologies.orient.core.db.document.odatabasedocumenttx.load(odatabasedocumenttx.java:1739) 在com.orientechnologies.orient.core.db.document.odatabasedocumenttx.load(odatabasedocumenttx.java:103) 在com.orientechnologies.orient.core.id.orecordid.getRecord(orecordid.java:329) 在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) 在com.orientechnologies.orient.server.network.binary.binary.onetworkprotococolbinary.commit(onetworkprotococolbinary.java:1426) 在com.orientechnologies.orient.server.network.protocol.binary.onetworkprotococolbinary.executerequest(onetworkprotococolbinary.java:668) 在com.orientechnologies.orient.server.network.protocol.binary.onetworkprotococolbinary.sessionrequest(onetworkprotococolbinary.java:398) 在com.orientechnologies.orient.server.network.binary.binary.onetworkprotococolbinary.execute(onetworkprotococolbinary.java:217)) 在com.orientechnologies.common.thread.osoftthread.run(osoftthread.java:82)

最后,我得到了我的代码使用Univind函数

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选择和子Queries

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

http://orientdb.com/docs/last/sql-query.html#unwinding

谢谢,

最新更新