我正在尝试编写一个满足响应对象中两个要求的查询:
I'm trying to write a single query that satisfies two requirements in the response object:
必须包括顶点的 all 属性,而无需在查询中指定单个字段.
Must include all properties of a vertex, without specifying individual fields in the query.
必须在对象的同一级别上将结果展平.
Must flatten results at the same level on the object.
作为单独的查询,我可以这样做:
As separate queries, I can do:
g.V(1) .valueMap().by(unfold()).fold()响应:
{ "property1": "value1", "property2": "value2" }2. project查询
2. project query
g.V(1) .project("projectedProperty") .by(out("X").valueMap().by(unfold()).fold())响应:
{ "projectedProperty": "value", }组合查询
我尝试使用联合来合并这些结果:
Combined query
I've attempted to use a union to combine these results:
g.V(1) .union( valueMap().by(unfold()).fold(), // Query 1 project("projectedField").by(out("X").valueMap().by(unfold()).fold()) // Query 2 ).fold()响应:
{ [ { "property1": "value1", "property2": "value2" }, { "projectedProperty": "value" } ] }这种联合方法依赖于我在最后放一个折叠,这反过来又不能正确地合并/展平两个地图.预期的响应是:
This union approach relies on me putting a fold at the end, which in turn doesn't merge/flatten the two maps properly. Expected response is:
{ "property1": "value1", "property2": "value2", "projectedProperty": "value" }是否有更好的方法来完成在响应对象中合并/展平两个地图的任务?
Is there a better way to accomplish this task of merging/flattening two maps in the response object?
推荐答案典型的模式是unfold()将您的映射映射到条目(键/值),然后group()将它们重新映射为一个:
The typical pattern is to unfold() your maps to entries (keys/values) then group() them back together as one:
gremlin> g.V().has('person','name','marko'). ......1> union(project('count').by(outE().count()), elementMap()). ......2> unfold(). ......3> group().by(keys).by(select(values)) ==>[count:3,name:marko,label:person,id:1,age:29]更多推荐
合并格雷姆林地图
发布评论