我目前正在使用 TinkerPop Java API 进行图形遍历。目前我必须创建相同遍历的副本来计算计数。
Long allUsersCount = gt.V().hasLabel("user").has("name", "John").count().next();
List<Vertex> users = gt.V().hasLabel("user").has("name", "John").toList();
当我尝试重用 gt.V().hasLabel("user").has("name", "John").count()
返回的遍历来获取列表时,它导致了错误
java.lang.IllegalStateException: The traversal strategies are complete and the traversal can no longer be modulated
我只想知道是否有任何方法可以避免这种重复,因为这两种情况的遍历是相同的 gt.V().hasLabel("user").has("name", "John")
只是终止操作不同。
有没有办法将计数存储在中间(在 java 变量中)并继续遍历以获取用户列表。
最佳答案
count()
步骤是“减少障碍步骤”,这就是您看到自己所做行为的原因。有很多方法可以解决这个问题。这是一个使用航线数据集的示例。
gremlin> g.V().has('city','London').
fold().
project('cities','count').
by().
by(count(local))
==>[cities:[v[49],v[50],v[88],v[94],v[206],v[649]],count:6]
关于gremlin - TinkerPop 获取计数并继续相同的遍历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62176643/