简体   繁体   English

Gremlin 查询以检查给定外部 map 中是否存在值

[英]Gremlin query to check if a value exists in the given external map

I would like to traverse the graph until my node property value exist in the set.我想遍历图表,直到我的节点属性值存在于集合中。 Set contains id of the nodes and trivial objects. Set 包含节点和普通对象的 id。

The query is like:查询类似于:

public Map<String,Object> getNodes( Long startNodeID, Set<String, TraversedNode> mySet){
      return g.withSideEffect("x",mySet).V(startNodeID)
             .repeat( ...something )
             .choose( ...something )
             .until( myProperty is found in the given set  )
}

I have tried many things in the until part but couldn't get it.我在直到部分尝试了很多东西,但无法得到它。 Any suggestions to achieve?有什么建议可以实现吗? It maybe related to values and where keywords.它可能与值和 where 关键字有关。

values("id").where(P.within("x")) doesn't work values("id").where(P.within("x"))不起作用

Using the air-routes graph as sample data, a simple query can be written that looks for IDs within a provided set, as the query progresses.使用航线图作为样本数据,可以编写一个简单的查询,在查询进行时在提供的集合中查找 ID。 As mentioned in the comments, it is not 100% clear if this is what you are looking for but perhaps it will help with follow on questions.正如评论中提到的,这是否是您正在寻找的不是 100% 清楚,但也许它会帮助您解决问题。

gremlin> g.withSideEffect('s',[48,54,62,12]).
......1>   V(44).
......2>   repeat(out().simplePath()).
......3>   until(where(within('s')).by(id).by()).
......4>   path().
......5>   limit(5)

==>[v[44],v[8],v[48]]
==>[v[44],v[8],v[54]]
==>[v[44],v[8],v[12]]
==>[v[44],v[13],v[12]]
==>[v[44],v[13],v[48]] 

It may appear that you should just be able to do until(hasId(within('s'))) , but in that case 's' is treated as the literal string "s" and not a symbol representing the set called s .看起来您应该只能执行until(hasId(within('s'))) ,但在这种情况下's'被视为文字字符串“s”,而不是表示名为s的集合的符号。 When a predicate is nested inside a where step, as in where(within('s')) , Gremlin treats that as a special case and will treat s as the name of something declared earlier.当谓词嵌套在where步骤中时,例如where(within('s')) ,Gremlin 将其视为一种特殊情况,并将s视为之前声明的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM