合并格雷姆林地图

编程入门 行业动态 更新时间:2024-10-10 10:26:51
本文介绍了合并格雷姆林地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试编写一个满足响应对象中两个要求的查询:

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]
  • 更多推荐

    合并格雷姆林地图

    本文发布于:2023-11-29 09:36:43,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1646026.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:格雷   姆林   地图

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!