andrey.sh
andrey.sh

Reputation: 1

Compare sequential edge properties in TRAVERSE

I want to find the path between two vertices using TRAVERSE. But I need only edges with specific property which is greater than corresponding property from previous edge. For example, I want to use edges in the time order.

In gremlin I can do this:

select gremlin("current.as('x').outE('SentTo').as('c').inV.outE('SentTo').
filter{e, m -> m.get('c').getProperty('time') <= e.getProperty('time')}.
inV.loop('x'){it.object.getProperty('name') != 'John' && it.loops < 10}.
path.filter{it.last().getProperty('name') =='John'}")
FROM (SELECT FROM Person WHERE name = 'Bill')

But almost every gremlin query in orientdb lasts forever and the given query crashes with GC overhead error.

To compare, the query below takes about 5 seconds (my db has about 1M vertices and 2M edges):

SELECT
  $path
FROM
  (TRAVERSE 
     out('SentTo')
   FROM
     (SELECT FROM Person WHERE name = 'John')
   WHILE
     $depth < 10)
WHERE (SELECT FROM Person WHERE name = 'Bill')

So, I want to know how to modify TRAVERSE query to compare time between edges or (hardly) how to optimize gremlin query

Thanks

Upvotes: 0

Views: 93

Answers (1)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

I think I've heard that OrientDB finally supports TinkerPop3. If that's the case, then consider to use the following traversal:

g.V().has("Person", "name", "Bill").
  repeat(outE().or(__.not(select("e")),
                   __.where(gte("e")).by("time")).as("e").otherV()).
   until(has("name", "John").or().loops().is(gte(10))).has("name", "John").path().limit(1)

Upvotes: 2

Related Questions