Get visited edges in OrientDB's shortestPath()

2019-03-29 05:04发布

I am new to OrientDB and I want to use the new shortestPath() method to get the edges that are between two vertices.

What I do is:

OSQLSynchQuery<T> sql = new OSQLSynchQuery<T>("select shortestpath(" + firstVertex + ", " + secondVertex + ").asString()");

List<ODocument> execute = db.query(sql);

and what I can only get is [#-2:1{shortestpath:[#8:1, #8:3]} v0].

So, I wanted to know how could I extract the edges (well, only one edge in this case, because these two vertices are directly connected) from this output or from the output that I get without asString():

[#-2:1{shortestpath:[2]} v0]

Thanks in advance!

3条回答
成全新的幸福
2楼-- · 2019-03-29 05:08

OrientDB has collection and map types. To make a collection the result set (what you're interested) you've to flatten it:

select flatten( shortestpath(" + firstVertex + ", " + secondVertex + ") )

To get the edges outgoing edges there are so many ways. Below a few of them:

select vertices.out from (
   select flatten( shortestpath(" + firstVertex + ", " + secondVertex + ") ) as vertices
)

Or also:

select flatten( shortestpath(" + firstVertex + ", " + secondVertex + ").out )
查看更多
闹够了就滚
3楼-- · 2019-03-29 05:18

For me, it didn't work how dante or Lvca explained it:

select flatten(shortestPath) from (select shortestPath(#12:0,#12:2,'BOTH')

This lead to errors in the console or to no records returned in the OrientDB Studio.

Instead, when I used an alias for the function result, it worked finally. So maybe try out this form:

select flatten(sp) from (select shortestPath(#12:0,#15:2,'BOTH') as sp)

(Note. I'm using v1.7.4)

查看更多
叼着烟拽天下
4楼-- · 2019-03-29 05:30

Try

select expand(shortestPath) from (select shortestPath(" + firstVertex + ", " + secondVertex + "))

You will receive vertices.

查看更多
登录 后发表回答