How to get tuples in gremlin?

299 views Asked by At

How can I get Gremlin return a tuple. I want to get 2 attributes from vertices at a time and then sort these tuples on one of the attributes. How can I do that.

Also how can analytics be applied to titan graphs....

1

There are 1 answers

3
stephen mallette On BEST ANSWER

For the first part of your question regarding tuples - just transform to a two (or more) item list of your properties:

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.V.has('age').transform{[it.name,it.age]} 
==>[marko, 29]
==>[vadas, 27]
==>[josh, 32]
==>[peter, 35]

then to sort, just use order step and pick the item in the tuple to order by...in this case "name":

gremlin> g.V.has('age').transform{[it.name,it.age]}.order{it.a[0]<=>it.b[0]}
==>[josh, 32]
==>[marko, 29]
==>[peter, 35]
==>[vadas, 27]

and in this case "age":

gremlin> g.V.has('age').transform{[it.name,it.age]}.order{it.a[1]<=>it.b[1]}    
==>[vadas, 27]
==>[marko, 29]
==>[josh, 32]
==>[peter, 35]