【问题标题】:Gremlin: select().count() always returns 1 when called inside choose()Gremlin:select().count() 在choose() 中调用时总是返回1
【发布时间】:2020-07-19 01:07:46
【问题描述】:

select("anything").count() 在choose() 中调用时总是返回1

为什么会这样?是否有任何优雅且不慢的解决方法来解决这个问题? “优雅而不慢”是指我不必写两次搜索的解决方案,因为我不能使用 select() 返回。

您可以在 gremlin 控制台上使用以下代码自行测试:

g.addV("test1")
g.addV("test2")
g.addV("test3")

count 有效,因为不使用 select:

g.V().as("result").choose(V().count().is(gt(1)), constant("greater than 1"), constant("not greater than 1"))

计数不起作用,因为被计数的元素来自选择:

g.V().as("result").choose(select("result").count().is(gt(1)), constant("greater than 1"), constant("not greater than 1"))

【问题讨论】:

    标签: gremlin tinkerpop tinkerpop3 gremlin-server


    【解决方案1】:

    select 步骤用于返回遍历中的某个点。由于每个顶点都作为自己的遍历,因此您将始终只选择 1 个顶点。

    你应该fold“结果”值,然后count它们。

    g.V().fold().as('result')
      choose(
        select('result').
        count(local).is(gt(1)),
        constant('greater than 1'),
        constant('not greater than 1')
      )
    

    示例:https://gremlify.com/i0z0zqucgz

    【讨论】:

      猜你喜欢
      • 2011-04-06
      • 2018-05-13
      • 1970-01-01
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      • 2011-02-02
      • 1970-01-01
      相关资源
      最近更新 更多