简体   繁体   English

gremlin python 克隆遍历

[英]gremlin python clone traversal

I'm using gremlin-python to connect to gremlin-server and I'm trying to build up a query incrementally but I'm getting stuck.我正在使用 gremlin-python 连接到 gremlin-server 并且我正在尝试逐步建立一个查询,但我遇到了困难。 I have an initial part of my query like the following:我的查询有一个初始部分,如下所示:

query = g.V().hasLabel('<some_label>')

Now I would like to do multiple things with this query, firstly I just want a count:现在我想用这个查询做很多事情,首先我只想要一个计数:

query.count().next()

Now if I do anything else using the query variable the count step is on the traversal, so something like the following doesn't work:现在,如果我使用query变量执行任何其他操作,则计数步骤在遍历中,因此类似以下内容不起作用:

query.out('<some_edge_label>').valueMap().toList()

Looking at the docs it seems like I need to clone the traversal so I replaced the above with:查看文档似乎我需要克隆遍历,所以我将上面的内容替换为:

query = g.V().hasLabel('<some_label>')

count_query = query.clone()
count_query.count().next()

But query still has the count() step on it, when I print the bytecode even though I cloned it.但是当我打印字节码时,即使我克隆了它, query仍然有count()步骤。 Is this the expected behaviour for gremlin-python?这是 gremlin-python 的预期行为吗? Here is a complete example of what I'm talking about, printing the bytecode at each step:这是我正在谈论的完整示例,在每个步骤中打印字节码:

query = g.V().hasLabel('alabel')
print(query)
q_count = query.clone()
print(q_count.count())
print(query)

[['V'], ['hasLabel', 'alabel']]
[['V'], ['hasLabel', 'alabel'], ['count']]
[['V'], ['hasLabel', 'alabel'], ['count']]

What do I do to clone/copy the start of the traversal so I can reuse it in gremlin-python?我该怎么做才能克隆/复制遍历的开始,以便我可以在 gremlin-python 中重用它?

It looks like this issue was a bug in gremlin-python and has been fixed in version 3.4.7.看起来这个问题是 gremlin-python 中的一个错误,并已在版本 3.4.7 中修复。 Updating the version solved my issue.更新版本解决了我的问题。

There were some fixes in the area of deep cloning traversals in the 3.4.7 (3.3.11) [1] [2] Apache TinkerPop release (June 2020).在 3.4.7 (3.3.11) [1] [2] Apache TinkerPop 版本(2020 年 6 月)中,对深度克隆遍历区域进行了一些修复。 Installing one of those drivers should help.安装其中一个驱动程序应该会有所帮助。

[1] https://github.com/apache/tinkerpop/blob/master/CHANGELOG.asciidoc [1] https://github.com/apache/tinkerpop/blob/master/CHANGELOG.asciidoc

[2] https://issues.apache.org/jira/browse/TINKERPOP-2350 [2] https://issues.apache.org/jira/browse/TINKERPOP-2350

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

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