我想在gremlin中转换以下密码查询,但在使用union时会遇到问题。
match d=(s:Group{id:123})<-[r:Member_Of*]-(p:Person) with d,
RELATIONSHIPS(d) as rels
WHERE NONE(rel in rels WHERE EXISTS(rel.`Ceased On`))
return *
UNION
match d=(s:Group{id:123})<-[r:Member_Of*]-(p:Group)-[r1:
Member_Of*]->(c:Group) with d,
RELATIONSHIPS(d) as rels
WHERE NONE(rel in rels WHERE EXISTS(rel.`Ceased On`))
return *
UNION
match d=(c:Group{id:123})-[r:Member_Of*]->(p:Group) with d,
RELATIONSHIPS(d) as rels
WHERE NONE(rel in rels WHERE EXISTS(rel.`Ceased On`))
return *
UNION
match d=(s:Group{id:123})<-[r:Member_Of*]-(p:Group)<-[r1:
Member_Of*]-(c:Person) with d,
RELATIONSHIPS(d) as rels
where NONE(rel in rels WHERE EXISTS(rel.`Ceased On`))
return *在上面的密码查询中,源顶点是Group,它有id '123',所以对于传入和输出边缘,我创建了下面的gremlin查询。
g.V().hasLabel('Group').has('id',123)
union(
__.inE('Member_Of').values('Name'),
__.outE('Member_Of').values('Name'))
.path() 现在,我必须遍历顶点的传入边缘,在上面的查询中,这个顶点是源顶点的传入顶点,在这里,我混淆了联合语法。
请帮助,谢谢:)
发布于 2021-10-28 15:32:46
Cypher查询的这一部分
match d=(s:Group{id:123})<-[r:Member_Of*]-(p:Group)<-[r1:Member_Of*]-(c:Person)在Gremlin中,可以表示为
g.V().has('Group','id',123).
repeat(inE('Member_Of').outV()).until(hasLabel('G')).
repeat(inE('Member_Of').outV()).until(hasLabel('Person')).
path().
by(elementMap())如果没有真正涉及多个跳(例如,在Cypher中,如果您真的不需要'*'),您可以删除repeat构造,只保留inE和outV步骤。无论如何,Gremlin的这一点将为您提供节点和边缘(关系)以及它们的所有属性等,因为路径将包含它们的elementMap。
请注意,从Cypher到Gremlin的直接端口可能无法充分利用目标数据库。例如,许多启用Gremlin的商店允许用户提供(实际) ID值。这使得查询效率大大提高,因为您可以使用以下内容:
g.V('123')直接找到一个顶点。
如果没有完全解除您的障碍,请在下面添加一个注释。
更新: 2021-10-29
我使用air数据集测试查询模式是否有效,使用以下查询:
g.V().has('airport','code','AUS').
repeat(inE('contains').outV()).until(hasLabel('country')).limit(1).
repeat(outE('contains').inV()).until(hasLabel('airport')).limit(3).
path().
by(elementMap())https://stackoverflow.com/questions/69743181
复制相似问题