首页 > 解决方案 > 查询返回错误值

问题描述

我正在和 Gremlin 一起测试和研究海王星。我创建了几个 User 类型的节点,它们只有一个id和一个email. 如果我对他们进行原始查询,我会得到:

// http://my-neptune/?gremlin=g.V().hasLabel('User')

  "result": {
    "data": {
      "@type": "g:List",
      "@value": [
        {
          "@type": "g:Vertex",
          "@value": {
            "id": "u01",
            "label": "User",
            "properties": {
              "email": [
                {
                  "@type": "g:VertexProperty",
                  "@value": {
                    "id": {
                      "@type": "g:Int32",
                      "@value": 2051025270
                    },
                    "value": "User01@email.com",
                    "label": "email"
                  }
                }
              ]
            }
          }
        },
        {
          "@type": "g:Vertex",
          "@value": {
            "id": "u02",
            "label": "User",
            "properties": {
              "email": [
                {
                  "@type": "g:VertexProperty",
                  "@value": {
                    "id": {
                      "@type": "g:Int32",
                      "@value": -374298315
                    },
                    "value": "user02@mail.com",
                    "label": "email"
                  }
                }
              ]
            }
          }
        }
      ]
    }

我不想用visjs来表示这个图。所以我想为每个节点返回基本上 3 个属性:

为此,我正在执行以下查询:

g.V()
    .hasLabel('User')
    .project('id', 'label', 'group')
    .by(T.id)
    .by(
        union(id(), values('email'))
        .fold()
    )
    .by(T.label)

但结果并不如预期。label我只为第一个节点获得正确的投影,其他节点为空:

  "result": {
    "data": {
      "@type": "g:List",
      "@value": [
        {
          "@type": "g:Map",
          "@value": [
            "id",
            "u01",
            "label",
            {
              "@type": "g:List",
              "@value": [
                "u01",
                "User01@email.com"
              ]
            },
            "group",
            "User"
          ]
        },
        {
          "@type": "g:Map",
          "@value": [
            "id",
            "u02",
            "group",
            "User",
            "label",
            {
              "@type": "g:List",
              "@value": [
                // This list should not be empty 
              ]
            }
          ]
        }
      ]
    }

任何想法为什么会发生这种情况或我如何执行类似的任务?

标签: graph-databasesgremlintinkerpopamazon-neptune

解决方案


添加一个答案,以便在提到的新版本确实解决了问题时可以接受评论中提出的解决方案。

将 Neptune 实例升级到https://docs.aws.amazon.com/neptune/latest/userguide/engine-releases-1.0.2.1.R4.html应该可以解决该问题。


推荐阅读