Gremlin 按属性分组子顶点
我将Amazon Neptune与以下简单的图形模式结合使用:Gremlin 按属性分组子顶点,gremlin,amazon-neptune,Gremlin,Amazon Neptune,我将Amazon Neptune与以下简单的图形模式结合使用: 根目录--具有-->子目录 其中根顶点可以具有许多不同的属性 我需要一个查询来创建一个字典,其中包含所有作为键的根顶点属性以及具有相同值的所有子顶点的数组 例如,使用以下数据: { root: { a: 1 b: 2 c: 3 }, child1: { a: 4 b: 2 c: 3 }, child2: { a: 1 b: 4 c: 3 } } 我将得到
根目录--具有-->子目录
其中根顶点可以具有许多不同的属性
我需要一个查询来创建一个字典,其中包含所有作为键的根顶点属性以及具有相同值的所有子顶点的数组
例如,使用以下数据:
{
root: {
a: 1
b: 2
c: 3
},
child1: {
a: 4
b: 2
c: 3
},
child2: {
a: 1
b: 4
c: 3
}
}
我将得到以下结果:
{
a: [child2],
b: [child1],
c: [child1, child2]
}
当我知道这些属性时,我可以这样做:
g.V().hasLabel('Root').as('root')
.project('a', 'b', 'c')
.by(out('has').where(eq('root')).by('a').fold())
.by(out('has').where(eq('root')).by('b').fold())
.by(out('has').where(eq('root')).by('c').fold())
有没有一种方法可以在不知道根属性的情况下创建它?也许有一种比这更优雅的解决方案,但这正是我的尝试:
g.V().hasLabel('Root').as('root').
properties().as('prop').
group().by(label).
by(select('root').
out('has').where(properties().and(
where(eq('prop')).by(key),
where(eq('prop')).by(value)
)).
fold())
示例:也许有比这更优雅的解决方案,但这是我的尝试:
g.V().hasLabel('Root').as('root').
properties().as('prop').
group().by(label).
by(select('root').
out('has').where(properties().and(
where(eq('prop')).by(key),
where(eq('prop')).by(value)
)).
fold())
例如: