我想根据以下条件返回用户的不同git分支:
因此,请考虑以下示例数据,
user = graph.addVertex(label, 'User', 'name', 'John')
branch1 = graph.addVertex(label, 'Branch', 'name', 'branch1')
branch2 = graph.addVertex(label, 'Branch', 'name', 'branch2')
branch3 = graph.addVertex(label, 'Branch', 'name', 'branch3')
branchmaster = graph.addVertex(label, 'Branch', 'name', 'master')
user.addEdge('AUTHOR_OF', branch1)
user.addEdge('AUTHOR_OF', branch2)
user.addEdge('AUTHOR_OF', branch3)
user.addEdge('AUTHOR_OF', branchmaster)
pr2 = graph.addVertex(label, 'PullRequest', 'name', 'pr2', 'state', 'OPEN')
pr3 = graph.addVertex(label, 'PullRequest', 'name', 'pr3', 'state', 'DECLINED')
branch2.addEdge('SOURCE_OF', pr2)
branch3.addEdge('SOURCE_OF', pr3)
pr22 = graph.addVertex(label, 'PullRequest', 'name', 'pr22', 'state', 'MERGED')
branch2.addEdge('SOURCE_OF', pr22)
pr23 = graph.addVertex(label, 'PullRequest', 'name', 'pr23', 'state', 'DECLINED')
branch2.addEdge('SOURCE_OF', pr23)
我想返回branch1(因为没有关联的PR)和branch3(因为关联的PR被拒绝)
以下查询不适用于AWS Neptune,因为Neptune不支持lambda步骤:
g.V().hasLabel('User')
.out('AUTHOR_OF')
.hasLabel('Branch')
.has('name', neq('master'))
.where(out('SOURCE_OF')
.hasLabel('PullRequest').values('state').fold()
.filter{ !(it.get().contains('OPEN') || it.get().contains('MERGED')) })
.dedup()
.order().by('updated_at', desc)
答案 0 :(得分:2)
您可以改为使用within
谓词:
g.V().hasLabel('User')
.out('AUTHOR_OF')
.hasLabel('Branch')
.has('name', neq('master'))
.where(__.not(out('SOURCE_OF').hasLabel('PullRequest').has('state', within(['OPEN','MERGED']))))
.dedup()
.order().by('updated_at', desc)