如何使用 Gremlin 3 删除具有特定 inVertices 的传出边?
How to drop outgoing edges except those with specific inVertices using Gremlin 3?
如果它们的 inVertices 不包含在 donttouch
的列表中,我想删除顶点 entity
的出边。
我有这样的遍历:
g.V(id).as("entity")
.V(id2).as("donttouch1")
.V(id3).as("donttouch2")
.outE("hasType").drop();
以上查询存在三个问题:
- 需要对要丢弃的边进行过滤
- 它需要以某种方式回溯到
entity
,因此 outE("hasType")
边从 entity
而不是最后一个 donttouch
出来。我认为在 TinkerPop 2 中 back('x')
step 是可能的
- 它需要在 drop()
之后 return entity
返回
所以我需要这样的东西:
String[] donttouch= {"donttouch1","donttouch1"};
g.V(id).as("entity")
.V(id2).as("donttouch1")
.V(id3).as("donttouch2")
.back("entity").outE("hasType")
.where(not(inV().hasId(P.within(donttouch)))).drop().select("entity").next()
donttouch
s 的列表可能很长,所以我宁愿把它们放在一起,而不是作为 neq
s
的连词
谢谢!
我假设 untouchable ids 列表已经存在于列表/集合中。在这种情况下你可以这样做:
g.withSideEffect("x", untouchableIds).
V(id).outE("hasType").not(inV().id().where(within("x"))).drop()
如果它们的 inVertices 不包含在 donttouch
的列表中,我想删除顶点 entity
的出边。
我有这样的遍历:
g.V(id).as("entity")
.V(id2).as("donttouch1")
.V(id3).as("donttouch2")
.outE("hasType").drop();
以上查询存在三个问题:
- 需要对要丢弃的边进行过滤
- 它需要以某种方式回溯到
entity
,因此outE("hasType")
边从entity
而不是最后一个donttouch
出来。我认为在 TinkerPop 2 中back('x')
step 是可能的
- 它需要在 drop() 之后 return
entity
返回
所以我需要这样的东西:
String[] donttouch= {"donttouch1","donttouch1"};
g.V(id).as("entity")
.V(id2).as("donttouch1")
.V(id3).as("donttouch2")
.back("entity").outE("hasType")
.where(not(inV().hasId(P.within(donttouch)))).drop().select("entity").next()
donttouch
s 的列表可能很长,所以我宁愿把它们放在一起,而不是作为 neq
s
谢谢!
我假设 untouchable ids 列表已经存在于列表/集合中。在这种情况下你可以这样做:
g.withSideEffect("x", untouchableIds).
V(id).outE("hasType").not(inV().id().where(within("x"))).drop()