Abu*_*ham 6 group-by limit gremlin azure-cosmosdb-gremlinapi
我正在尝试运行gremlin 查询,该查询将某个标签的顶点按某个字段分组为多个组(假设它是“displayName”),并将组数限制为n并且每个组中的项目数也限制为n。
有没有办法实现这一目标?
由于 group().by() 返回项目列表,我尝试使用 expand() 然后对内部项目应用限制。我设法限制了返回的组数,但无法限制每个组中的项目数。
这是我用来限制组数的查询:
gV().hasLabel('customLabel').group().by('displayName').unfold().limit(n)
// Expected result:(if n == 2)
[
{
"displayName1": [
{ // item 1 in first group
},
{ // item 2 in first group
}
]
},
{
"displayName2": [
{ // item 1 in second group
},
{ // item 2 in second group
}
]
}
]
// Actual result: (when n == 2)
[
{
"displayName1": [
{ // item 1 in first group
},
{ // item 2 in first group
},
... // all the items are included in the result
]
},
{
"displayName2": [
{ // item 1 in second group
},
{ // item 2 in second group
},
... // all the items are included in the result
]
}
]
Run Code Online (Sandbox Code Playgroud)
目前,通过上面的查询,我只得到 2 个组“displayName1”和“displayName2”,但每个组都包含其中的所有项目,而不仅仅是预期的 2 个。
如果您想限制答案,可以通过定义组中每个键的值来实现:
g.V().hasLabel('customLabel')
.group()
.by('displayName')
.by(identity().limit(n).fold())
.unfold().limit(n)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
840 次 |
| 最近记录: |