[英]Gremlin query group by clause
I am using neptune graph database.我正在使用海王星图形数据库。 Need help writing a query with a group by clause.
需要帮助编写带有 group by 子句的查询。
We have three nodes我们有三个节点
CAMPAIGN → AD → LP活动 → 广告 → LP
Campaign to Ad is 1 to many mapping AD to LP is 1 to 1 mapping Campaign 到 Ad 是一对多的映射 AD 到 LP 是一对一的映射
Suppose we have the following vertices and associations假设我们有以下顶点和关联
C1 → A1 → LP1
C1 → A2 → LP1
C2 → A3 → LP1
C2 → A4 → LP1
C3 → A5 → LP2
I want my result set to look like this.我希望我的结果集看起来像这样。
[
{
"lp": "LP1",
"campaigns": [
{aId: "A1", cId: "C1"},
{aId: "A2", cId: "C1"},
{aId: "A3", cId: "C2"},
{aId: "A4", cId: "C2"}
]
},
{
"lp": "LP2",
"campaigns": [
{aId: "A5", cId: "C3"}
]
}
]
Any help would be greatly appreciated.任何帮助将不胜感激。
Something like this should work, group
by the LPs and then by the paths from them.像这样的东西应该可以工作,按 LPs
group
,然后按它们的路径分组。
g.V().hasLabel('LP').
group().
by(id).
by(__.in().in().path().by('aId').by('cId').fold())
Note that if possible, use the edge labels for the in()
steps.请注意,如果可能,请在
in()
步骤中使用边缘标签。 This will help the query planner only pick relevant edges to traverse over.这将帮助查询规划器只选择相关的边来遍历。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.