4

I wanted minimum and maximum length of the two different connected node types nodes. I got two different queries but both are slow, I want it to be fast.

1st :> This giving me correct ans.

g.withSack(0).V().hasLabel("People").as("from","to").
                repeat(both().as("to").dedup("from","to").
                sack(sum).by(constant(1))).
                emit(hasLabel("People")).
                sack().dedup().fold().
                project("min", "max").
                by(choose(count(local).is(0), constant(0), min(local))).
                by(choose(count(local).is(0), constant(0), max(local)))

and

2nd:> This gives me adding from nodes to the length( means min+1, and max+1)

g.V().hasLabel("People")
            .as("from" ,"to" )
            .repeat(both().as("to").dedup("from", "to")).emit(hasLabel("People")).hasLabel("People")
            .select(all, "to").count(local).dedup().as("len").fold()
            .project("min", "max")
            .by(choose(count(local).is(0), constant(0), min(local)))
            .by(choose(count(local).is(0), constant(0), max(local)))

Both query taking the same time for execution, but slow as per the neo4j cypher query does. Gremlin execution time is 50 times more than cypher query. Here is the cypher query

Ravindra Gupta
  • 1,256
  • 12
  • 42
  • What's the Cypher query that you're using for the comparison? Any chance you can add that to your question? – Daniel Kuppitz Jun 01 '18 at 17:36
  • https://stackoverflow.com/a/49174562/1897935 – Ravindra Gupta Jun 02 '18 at 06:09
  • Well, then that's not really comparable. You compare a pure query solution against a stored procedure (or a VertexProgram in TinkerPop terms). A VertexProgram can easily outperform a pure query based solution as it can do things much more efficiently. I am currently working on a VP for shortest paths, but I guess it will take some more time until it makes it into a release. – Daniel Kuppitz Jun 02 '18 at 17:25

0 Answers0