在 gremlin 中合并地图列表
Merging list of maps in gremlin
我有这样的关系:
person --likes--> subject
这是我的查询:
g.V().
hasLabel('person').
has('name', 'Joe').
outE('likes').
range(0, 2).
union(identity(), inV().hasLabel('subject')).
valueMap('rating', 'name').
此时,我得到如下所示的结果:
[
{
"rating": 3.236155563
},
{
"rating": 3.162886797
},
{
"name": "math"
},
{
"name": "history"
}
]
我想要这样的东西:
[
{
"rating": 3.236155563,
"name": "math"
},
{
"rating": 3.162886797,
"name": "history"
},
]
我已经尝试对结果进行分组 - 这给了我想要的结构 - 但由于相同的键,我只得到一组结果。
当您 post 创建图表的代码时,它总是有帮助,因此我们可以为您提供经过测试的答案。像这样
g.addV('person').property('name', 'P1').as('p1').
addV('subject').property('name', 'Math').as('math').
addV('subject').property('name', 'History').as('history').
addV('subject').property('name', 'Geography').as('geography').
addE('likes').from('p1').to('math').property('rating', 1.2).
addE('likes').from('p1').to('history').property('rating', 2.3).
addE('likes').from('p1').to('geography').property('rating', 3.4)
我相信你正在尝试写一个遍历,从某个人开始,沿着前两个“喜欢”的边出去,得到他喜欢的主题的名称和相应“喜欢”的评分边。
g.V().has('person', 'name', 'P1').
outE('likes').
range(0, 2).
project('SubjectName', 'Rating').
by(inV().values('name')).
by(values('rating'))
我有这样的关系:
person --likes--> subject
这是我的查询:
g.V().
hasLabel('person').
has('name', 'Joe').
outE('likes').
range(0, 2).
union(identity(), inV().hasLabel('subject')).
valueMap('rating', 'name').
此时,我得到如下所示的结果:
[
{
"rating": 3.236155563
},
{
"rating": 3.162886797
},
{
"name": "math"
},
{
"name": "history"
}
]
我想要这样的东西:
[
{
"rating": 3.236155563,
"name": "math"
},
{
"rating": 3.162886797,
"name": "history"
},
]
我已经尝试对结果进行分组 - 这给了我想要的结构 - 但由于相同的键,我只得到一组结果。
当您 post 创建图表的代码时,它总是有帮助,因此我们可以为您提供经过测试的答案。像这样
g.addV('person').property('name', 'P1').as('p1').
addV('subject').property('name', 'Math').as('math').
addV('subject').property('name', 'History').as('history').
addV('subject').property('name', 'Geography').as('geography').
addE('likes').from('p1').to('math').property('rating', 1.2).
addE('likes').from('p1').to('history').property('rating', 2.3).
addE('likes').from('p1').to('geography').property('rating', 3.4)
我相信你正在尝试写一个遍历,从某个人开始,沿着前两个“喜欢”的边出去,得到他喜欢的主题的名称和相应“喜欢”的评分边。
g.V().has('person', 'name', 'P1').
outE('likes').
range(0, 2).
project('SubjectName', 'Rating').
by(inV().values('name')).
by(values('rating'))