使用图形遍历的一部分的属性作为另一部分的筛选器



我想要下一个:

  1. 遍历图的一部分
  2. 从第一次遍历获取属性
  3. 将其作为过滤器放入其他遍历中
  4. 获取筛选值

当我在Gremlin控制台中运行下一个时:

g = TinkerGraph.open().traversal()
g.addV('a').property(id, 1).property('b',2)
g.addV('a').property(id, 2).property('b',2).property('c',3)
g.V(2).properties().key().limit(1).as('q').select('q')
g.V(2).properties().key().limit(1).as('q').V(1).properties().key()
g.V(2).properties().key().limit(1).as('q').V(1).properties().key().select('q')
g.V(2).properties().key().limit(1).as('q').V(1).properties().key().where(__.is('b'))
g.V(2).properties().key().limit(1).as('q').V(1).properties().key().where(__.is(select('q')))

我得到:

gremlin>     g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin>     g.addV('a').property(id, 1).property('b',2)
==>v[1]
gremlin>     g.addV('a').property(id, 2).property('b',2).property('c',3)
==>v[2]
gremlin>     g.V(2).properties().key().limit(1).as('q').select('q')
==>b
gremlin>     g.V(2).properties().key().limit(1).as('q').V(1).properties().key()
==>b
gremlin>     g.V(2).properties().key().limit(1).as('q').V(1).properties().key().select('q')
==>b
gremlin>     g.V(2).properties().key().limit(1).as('q').V(1).properties().key().where(__.is('b'))
==>b
gremlin>     g.V(2).properties().key().limit(1).as('q').V(1).properties().key().where(__.is(select('q')))
gremlin>

所以我可以看到:

  1. 我的第一个遍历路径得到了'b'的属性
  2. 通过直接使用文字"b"进行选择
  3. 使用投影按"b"进行筛选不起作用

所以问题是,在上述情况下,如何使用遍历的一部分中的值作为其他遍历的过滤器

我的用例是我有一个prototype顶点。我想抓取它的所有属性(可能是值(,并找到与prototype相似的所有顶点。

另一种选择是将查询存储在prototype的属性中,读取并评估它以获得经过它过滤的顶点

我知道我可以进行字符串的应用程序端连接,但我只想停留在Gremlin的无代码部分,以具有适当的提供者可移植性。

更新:

官方文件示例:

gremlin> firstYear = g.V().hasLabel('person').
local(properties('location').values('startTime').min()).
max().next()
==>2004
gremlin> l = g.V().hasLabel('person').as('person').
properties('location').or(has('endTime',gt(firstYear)),hasNot('endTime')).as('location').
valueMap().as('times').
select('person','location','times').by('name').by(value).by().toList()

如何在控制台中没有变量的情况下使用firstYear,而是从查询中引用它?

我看到你的问题在Gremlin用户列表中得到了回答。[1] 将答案复制到此处,以供其他可能搜索同一问题的人使用。

您正在寻找的是:

g.V(2).properties().key().limit(1).as('q').V(1).properties().key().where(eq('q'))

请参阅Where步骤的文档,以了解Where的不同使用模式。

[1]https://groups.google.com/forum/#!主题/gremlin用户/f1NfwUw9ZVI

相关内容

最新更新