thinkaurelius / neo4j-gremlin-plugin

Gremlin for Neo4jServer 2.x
http://thinkaurelius.com
Apache License 2.0
30 stars 14 forks source link

Gremlin script only partially executed #7

Closed NitinJamadagni closed 9 years ago

NitinJamadagni commented 9 years ago

I am trying to add an edge if it does not exist , else update it's weight

         new File("apps.txt").eachLine { line ->
        vno=g.V.has("appname",line).next().id;
        g.v(vno)_().ifThenElse{it.in("uses").has("identity",identity).count()==0}{g.addEdge(g.v(userno), it, "uses").sideEffect{it.weight=1}.iterate()}{g.v(vno).inE("uses").outV.has("identity",identity).back(2).sideEffect{it.weight=it.weight+1}.iterate()};

}

Apparently only the last app read by line closure,it's edge is getting updated

dkuppitz commented 9 years ago

Why do you think that this problem is related to the plugin?

NitinJamadagni commented 9 years ago

Hey, I think the issue it's with the plugin because on a gremlin repl shell using the TinkerGraph() it works just fine.But when run by making a curl request to the neo4j server with the plugin the results don't get logged(I checked the neo4j console logs as well)

Thanks Nitin On Apr 6, 2015 10:14 PM, "Daniel Kuppitz" notifications@github.com wrote:

Why do you think that this problem is related to the plugin?

— Reply to this email directly or view it on GitHub https://github.com/thinkaurelius/neo4j-gremlin-plugin/issues/7#issuecomment-90144612 .

dkuppitz commented 9 years ago

I don't think that this problem is caused by the plugin. Note that the REPL iterates your Gremlin pipeline automatically - in any other scenario you'll need to take care of it. Your pipeline is simply not iterated. Add .iterate() to your last statement or simply use this:

new File("apps.txt").eachLine { def line ->
    g.V().has("appname", line).sideEffect { def app ->
        def pipe = app.in("uses").has("identity", identity)
        if (pipe.hasNext()) {
            app.setProperty("weight", app.getProperty("weight") + 1)
        } else {
            g.v(userno).addEdge("uses", app, ["weight": 1])
        }
    }.iterate()
}
NitinJamadagni commented 9 years ago

Thanks Daniel, It worked after a .iterate() at the end. Should have read clearly about ->* REPL iterating the pipeline automatically and we having to take care of it in any other case*.

Thanks Nitin Jamadagni

On Tue, Apr 7, 2015 at 4:24 PM, Daniel Kuppitz notifications@github.com wrote:

Closed #7 https://github.com/thinkaurelius/neo4j-gremlin-plugin/issues/7 .

— Reply to this email directly or view it on GitHub https://github.com/thinkaurelius/neo4j-gremlin-plugin/issues/7#event-275107213 .