您可以project()
将元素放入Map
:
gremlin> g.V(1).project('name','age').by('name').by('age')
==>[name:marko,age:29]
by()
如您所见,采用这种方法可以在控制步进调制器中的属性时控制如何以更细粒度的方式生成贴图。如果返回的顶点没有同质的属性键,您将需要以某种方式考虑这一点 - 这是一种可能性:
gremlin> g.V().project('name','age').
......1> by('name').
......2> by(coalesce(values('age'),constant('none')))
==>[name:marko,age:29]
==>[name:vadas,age:27]
==>[name:lop,age:none]
==>[name:josh,age:32]
==>[name:ripple,age:none]
==>[name:peter,age:35]
如果不使用项目,您还可以执行以下操作:
gremlin> g.V().local(properties().group().by(key()).by(value()))
==>[name:marko,age:29]
==>[name:vadas,age:27]
==>[name:lop,lang:java]
==>[name:josh,age:32]
==>[name:ripple,lang:java]
==>[name:peter,age:35]
没有那么清楚project()
并且会得到通常不鼓励的所有属性,但显然这种方法会奏效。我想你可以逐项列出属性以获得如下:
gremlin> g.V().local(properties('name','age').group().by(key()).by(value()))
==>[name:marko,age:29]
==>[name:vadas,age:27]
==>[name:lop]
==>[name:josh,age:32]
==>[name:ripple]
==>[name:peter,age:35]