Orient DB在顶点之间创建边缘错误,顶点是使用Orient DB SQL函数读取的

问题描述 投票:0回答:1

我正面临一个问题,即在顶点之间创建边缘,其中一个顶点是通过使用orient SQL函数获得的,

以下是要求

假设我有3个顶点vertex1(@rid:#9:0),vertex2(@rid:#10:0),vertex3(@rid:#11:0),并且vertex1和vertex 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:com.orientechnologies.orient上com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.checkClusterSegmentIndexRange(OAbstractPaginatedStorage.java:4627)的数据库'test'中不存在集群段#-2。 com.orientechnologies.orient上的com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.readRecord(OAbstractPaginatedStorage.java:1404)中的.core.storage.impl.local.OAbstractPaginatedStorage.getClusterById(OAbstractPaginatedStorage.java:3013) .core.db.document.ODatabaseDocumentTx $ SimpleRecordReader.readRecord(ODatabaseDocumentTx.java:3411)位于com.orientechnologies.orient.core的com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.executeReadRecord(ODatabaseDocumentTx.java:2022) .tx.OTransactionOptimistic.loadRecord(OTransactionOptimistic.java:187)at com.orientechnologies.orient.core.tx.OTransactionOptimistic.loadRecord(OTransactionOptimistic.java:162)at com.orientechnologies.orient.cor e.tx.OTransactionOptimistic.loadRecord(OTransactionOptimistic.java:291)位于com.orientechnologies.orient.core.db.document的com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.load(ODatabaseDocumentTx.java:1739)。 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)在com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.begin(ODatabaseDocumentTx.java:1881)的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.executeRequest(ONetworkProtocolBinary.java:668)at com .orientechnologies.orient.server.network.protoc ol.binary.ONetworkProtocolBinary.sessionRequest(ONetworkProtocolBinary.java:398)com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.execute(ONetworkProtocolBinary.java:217)at com.orientechnologies.common.thread.OSoftThread。运行(OSoftThread.java:82)

orientdb
1个回答
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

谢谢,

© www.soinside.com 2019 - 2024. All rights reserved.