Good query for for edges regarding start and end vertex.

135 views
Skip to first unread message

Ray Neiheiser

unread,
Nov 30, 2016, 9:19:24 AM11/30/16
to OrientDB
I have some performance problems with reading edges depending on their start and end nodes. Is there a better way than checking every edges end vertex of every start vertex?

Iterable<Vertex> startNodes = getVertexList(relationshipStorage.getStartNode(), graph);
                Iterable<Vertex> endNodes = getVertexList(relationshipStorage.getEndNode(), graph);

                List<Edge> list = StreamSupport.stream(startNodes.spliterator(), false)
                        .flatMap(vertex1 -> StreamSupport.stream(vertex1.getEdges(Direction.OUT, relationshipId).spliterator(), false))
                        .filter(edge -> StreamSupport.stream(endNodes.spliterator(), false).anyMatch(vertex -> edge.getVertex(Direction.OUT).equals(vertex)))
                        .collect(Collectors.toList());

Oleksandr Gubchenko

unread,
Nov 30, 2016, 11:24:36 AM11/30/16
to OrientDB
Hi,  did you tried it using indexes?

Ray Neiheiser

unread,
Nov 30, 2016, 11:29:28 AM11/30/16
to OrientDB
No, I didn't but I can't just put an index for every node I have?

Isn't there any way like graph.getEdgeByVertex(startVertex, endVertex, properties) ?
Or anything which isn't the way like I resolved it above.

Ivan Mainetti

unread,
Nov 30, 2016, 5:19:45 PM11/30/16
to OrientDB
please help me understand, you need to search edges knowing start and end vertices?


Il giorno mercoledì 30 novembre 2016 15:19:24 UTC+1, Ray Neiheiser ha scritto:

Ray Neiheiser

unread,
Dec 1, 2016, 2:06:02 PM12/1/16
to orient-...@googlegroups.com
Exactly, I need to find edges knowing start and vertices and it's possible that I know edge label and property sometimes as well.
More accurately, I know a list of possible start and a list of possible end vertices.

Ivan Mainetti

unread,
Dec 1, 2016, 10:23:04 PM12/1/16
to OrientDB
not sure if this may work for you, but you could query via sql something like

select from E where out contains [<start-rid1>, <start-rid2>, <start-ridn>] and in contains [<end-rid1>, <end-rid2>, <end-ridn>] and <some-property>="something"



Il giorno mercoledì 30 novembre 2016 15:19:24 UTC+1, Ray Neiheiser ha scritto:

Ray Neiheiser

unread,
Dec 2, 2016, 8:07:29 PM12/2/16
to orient-...@googlegroups.com
That seems like an option.
But isn't there any option in gremlin/blueprints for it?

Titan also uses gremlin and I can use:

GraphTraversal<Vertex, Edge> tempOutput =  graph.traversal().V(nodeStartList.toArray()).bothE().filter(__.otherV().is(P.within(nodeEndList.toArray())));

Which will give me exactly what I want.

Ray Neiheiser

unread,
Dec 5, 2016, 12:39:45 PM12/5/16
to OrientDB
It's very strange also with:
StreamSupport.stream(startNodes.spliterator(), false).flatMap(vertex1 -> StreamSupport.stream(vertex1.getEdges(Direction.OUT, relationshipId).spliterator(), false)).collect(Collectors.toList())
It seems like I am unable to detect the outgoing edges of the vertices.
They seem to be all null.

I've added them like this:

Iterable<Vertex> startNodes = this.getVertexList(storage.getStartNode(), graph);
Iterable<Vertex> endNodes = this.getVertexList(storage.getEndNode(), graph);

for (Vertex startNode : startNodes)
{
for (Vertex endNode : endNodes)
{
String edgeClass = "class:" + storage.getId();
Edge edge = startNode.addEdge(edgeClass, endNode);

for (Map.Entry<String, Object> entry : storage.getProperties().entrySet())
{
edge.setProperty(entry.getKey(), entry.getValue());
}
edge.setProperty(Constants.TAG_HASH, HashCreator.sha1FromRelationship(storage));
edge.setProperty(Constants.TAG_SNAPSHOT_ID, snapshotId);
}
}
graph.commit(); And it only detect ingoing vertices not the outgoing ones.

Ray Neiheiser

unread,
Dec 11, 2016, 6:48:44 AM12/11/16
to OrientDB
Anyone has an idea?

Ray Neiheiser

unread,
Dec 14, 2016, 6:18:48 AM12/14/16
to OrientDB
I'd prefer a non sql solution for this.
Reply all
Reply to author
Forward
0 new messages