【发布时间】:2020-08-05 22:34:18
【问题描述】:
我正在运行 JanusGraph 服务器并从 gremlin 控制台连接到它。
可以看出,我有两个顶点,id属性设置为1和2
gremlin> g.addV('user').property('id', 1)
==>v[4224]
gremlin> g.addV('user').property('id', 2)
==>v[4192]
gremlin> g.V().valueMap()
==>{id=[2]}
==>{id=[1]}
接下来,我注入了一个具有不同属性的地图数组列表。我正在尝试遍历此地图并过滤顶点,但我无法弄清楚为什么查询不起作用。有人可以帮我找出正确的查询吗?
我尝试在 select("id") 之后使用终端步骤 next(),但也失败了。
gremlin> g.inject([["id": 1], ["id": 2, "something":"anything"]]).unfold().as("m").V().has("user", "id", select("m").select("id"))
Value [[SelectOneStep(last,m), SelectOneStep(last,id)]] is not an instance of the expected data type for property key [id] and cannot be converted. Expected: class java.lang.Integer, found: class org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal
Type ':help' or ':h' for help.
Display stack trace? [yN]
我不能使用g.V().has(label, key, within(...)),因为我需要在多个地方使用同一张地图并为每一行重复步骤。
【问题讨论】:
-
has(..., Traversal)被误解了。它旨在通过遍历 属性值 来过滤不产生结果的遍历器。这并不是说将select("m").select("id")的结果注入has()并使用该值来确定过滤器是否有效。使用Map遍历的最终目标是什么? -
@stephenmallette 最终目标是能够操纵几个顶点。假设输入是
[["id": 1, "something":"anything1"], ["id": 2, "something":"anything2"]]然后我希望能够一次性执行以下操作-> 找到 id 为“1”的用户顶点,然后去公司(大学)用户工作并在该顶点上添加任何属性1。 -> 找到 id 为“2”的用户顶点,然后去公司(大学)用户工作并在该顶点上添加属性anything2。 @stephenmallette
标签: gremlin janusgraph