1
votes

Am relatively new to graph.

Looking for help to build gremlin query equivalent 4 below sql.

Select a.x1,a.x2,b.y1,b.y2 from table1 a, table b where a.x1=b.y1 and a.x2=b.y2.

Consider table as vertices and x1 x2 y1 y2 as properties.

In janusgraph there are no edges for these vertices and property labels are also different. Before getting the result for , need to check if the vertices have no edges.

1

1 Answers

1
votes

If there are no edges, then this isn't a terribly "graphy" query so this might look a little clumsy. I think you would have to use some form of mid-traversal V(). I demonstrated here with a little data:

gremlin> g.addV('a').property('x1',1).property('x2',2).
......1>   addV('b').property('y1',1).property('y2',2).
......2>   addV('b').property('y1',2).property('y2',3).iterate()
gremlin> g.V().hasLabel('a').as('a').
......1>   V().hasLabel('b').as('b').
......2>   where('a', eq('b')).
......3>     by('x1').
......4>     by('y1').
......5>   where('a', eq('b')).
......6>     by('x2').
......7>     by('y2').
......8>   select('a','b').
......9>     by(valueMap(true))
==>[a:[label:a,id:0,x1:[1],x2:[2]],b:[label:b,id:3,y1:[1],y2:[2]]]

I'm not sure if there isn't a nicer way to do this. Depending on how large your dataset is, this could be a tremendously expensive traversal and would probably be a better candidate for a form of OLAP traversal using Gremlin Spark.