Java 在gremlin中,组结果是一对多关系
我必须输入国家和机场的类型,每个国家都有一个到多个标签为“hasAirport”的机场的优势 我正在尝试一个连接查询,它将返回按机场分组的国家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() 如果我的图表中只有一个国家,比如美国,有两个机场,那么查询
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())