Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在gremlin中,组结果是一对多关系_Java_Gremlin_Tinkerpop_Amazon Neptune - Fatal编程技术网

Java 在gremlin中,组结果是一对多关系

Java 在gremlin中,组结果是一对多关系,java,gremlin,tinkerpop,amazon-neptune,Java,Gremlin,Tinkerpop,Amazon Neptune,我必须输入国家和机场的类型,每个国家都有一个到多个标签为“hasAirport”的机场的优势 我正在尝试一个连接查询,它将返回按机场分组的国家 g.V().hasLabel("Country").as("country").out('hasAirport').as("airport").select("country", "airport").by(__.unfold().valueMap(true).fold()).toList() 如果我的图表中只有一个国家,比如美国,有两个机场,那么查询

我必须输入国家和机场的类型,每个国家都有一个到多个标签为“hasAirport”的机场的优势

我正在尝试一个连接查询,它将返回按机场分组的国家

g.V().hasLabel("Country").as("country").out('hasAirport').as("airport").select("country", "airport").by(__.unfold().valueMap(true).fold()).toList()
如果我的图表中只有一个国家,比如美国,有两个机场,那么查询结果如下

[   {
    "country": [
      {
        "name": "United States",
        "code": "USA",      "label": "Country",
        "id": 1565,
      }
    ],
    "airport": [
      {
        "id": 1234,
        "label": "Airport",
        "name": "San Francisco International Airport",      "code": "SFO"
      }
    ]   },   {
    "country": [
      {
        "name": "United States",
        "code": "USA",      "label": "Country",
        "id": 1565,
      }
    ],
    "airport": [
      {
        "id": 2345,
        "label": "Airport",
        "name": "Austin Bergstrom International Airport",       "code": "AUS"
      }
    ]   }  ]
有没有一种方法可以像下面这样将多个机场合并到一个阵列中

[
  {
    "country": [
      {
        "name": "United States",
        "code": "USA",
        "label": "Country",
        "id": 1565,
      }
    ],
    "airport": [
      {
        "id": 1234,
        "label": "Airport",
        "name": "San Francisco International Airport",
        "code": "SFO"
      },
      {
        "id": 2345,
        "label": "Airport",
        "name": "Austin Bergstrom International Airport",
        "code": "AUS"
      }
    ]
  }
 ]

您需要使用
项目

g.V().hasLabel("Country")
.project("country","airport")
.by(valueMap(true))
.by(out('hasAirport').valueMap(true).fold())

您需要使用
项目

g.V().hasLabel("Country")
.project("country","airport")
.by(valueMap(true))
.by(out('hasAirport').valueMap(true).fold())