How to define shortest-past search query that terminates on a first path found?

37 views
Skip to first unread message

Yevgeniy Ignatyev

unread,
Mar 20, 2018, 5:57:10 AM3/20/18
to Gremlin-users
Hello.

Currently I am struggling to make the following query for the shortest path to terminate in a reasonable amount of time:

g.V()
 
.has("name", fromName)
 
.repeat(__.both().simplePath())
 
.until(__.has("name", toName))
 
.limit(1)
 
.path()
 
.by("name")
 
.unfold()
 
.toList()

On our graph this query runs for minutes.

Limiting path length:

g.V()
 
.has("name", fromName)
 
.repeat(__.both().simplePath().or().loops().is(5))
 
.until(__.has("name", toName))
 
.limit(1)
 
.path()
 
.by("name")
 
.unfold()
 
.toList()

It outputs the actual shortest path in less than a second (real path is of length 3).
Can the query be rewritten without explicit path size limit so it will take the same amount of time?
Also, we have a kind of supernode (half of all the edges connected) in the graph through which the path goes, if it is what affects performance of the first query, how can it be determined why the second one completes so much faster?

Graph is stored in JanusGraph-Cassandra, "name" property indexed.

Best regards,
Evgeniy Ignatiev.

Daniel Kuppitz

unread,
Mar 20, 2018, 10:34:48 PM3/20/18
to gremli...@googlegroups.com
You need to kill all the inner repeat() traversers. In order to do that, you could emit the first match, store it in a collection and check this collection inside of until().

g.V().has("name", fromName).
  until(select("x").unfold()).
    repeat(both().simplePath()).
    emit(has("name", toName).store("x")).
  limit(1).
  path().
    by("name")

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/0d78f288-a2e6-4b19-9600-fc78f108b2ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yevgeniy Ignatyev

unread,
Mar 21, 2018, 7:01:23 AM3/21/18
to Gremlin-users
Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages