gremlinvertexedgesrexster

How to merge Two Vertex details and Edge Properties details Together in a single gremlin query


How to merge Two Vertex details and Edge Properties details Together in a single gremlin query.

I'm having two Vertices :

UserInfo vertex enter image description here

PostInfo vertex enter image description here

EdgeInfo Between them enter image description here

With Gremlin Query : g.v(2569472).out('_label','WallPost')[0..1]

enter image description here

I'm getting UserPost Vertex details , i want to add UserVertex detail in the response (i.e gender ) and Edge property detail in the response (i.e EdgeMessage)

I'm trying to compare sql equivalent innerjoin operation with gremlin from sql2gremlin but i'm not able to get the desired result.


Solution

  • SQL2Gremlin is written for TinkerPop 3, you're still using TinkerPop 2 (which is a lot more complicated IMO). Anyway, here's how you would do it in TP2:

    gremlin> g = TinkerGraphFactory.createTinkerGraph()
    ==>tinkergraph[vertices:6 edges:6]
    gremlin> g.v(1).outE("knows")
    ==>e[7][1-knows->2]
    ==>e[8][1-knows->4]
    gremlin> g.v(1).outE("knows").inV().retain([g.v(4)])
    ==>v[4]
    gremlin> g.v(1).as("x").outE("knows").as("y").inV().retain([g.v(4)]).select(["x","y"]) {it.map()} {it.weight}
    ==>[x:{name=marko, age=29}, y:1.0]