【问题标题】:does using many choose step effect the performance of the query gremlin Or How is a Choose step executed in gremlin使用许多选择步骤是否会影响查询 gremlin 的性能或如何在 gremlin 中执行选择步骤
【发布时间】:2017-02-13 06:17:35
【问题描述】:

我有一个简单的收藏查询,它告诉一个人是否喜欢一个项目

g.V().has('personId','3f857b1').choose(identity().out('favourite').has('itemId','48a680b'),constant('Already_favourite'),choose(V().has('itemId','48a680b'),constant('NotFavourite'),constant('InvalidItem')))

像在其他编程语言中那样编写嵌套选择步骤是一种不好的做法

我想知道我们是否可以在 gremlin 中实现存储过程

【问题讨论】:

  • 我个人觉得选择following if else或者switch implementation

标签: gremlin tinkerpop tinkerpop3


【解决方案1】:

编写嵌套选择步骤是一种不好的做法

不,但我仍然会以不同的方式编写您的查询。如果项目不存在,请不要浪费计算时间并快速停止遍历。另一方面,如果存在,则尝试通过其 id 找到它;不要为每个相邻顶点获取itemId 属性:

result = g.V().has('itemId', '48a680b').as('item').
           V().has('personId','3f857b1').coalesce(
                 out('favourite').where(eq('item')).constant('Already_favourite'),
                 constant('NotFavourite')).tryNext().orElse('InvalidItem');

【讨论】:

  • 谢谢丹尼尔,这个解释很有帮助
猜你喜欢
  • 1970-01-01
  • 2022-08-08
  • 2021-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多