对于给定的遍历gremlin查询,如何在所有访问的节点/边上应用静态方法 [英] How to apply a static has step on all the visited nodes/edges for a given traversal gremlin query

查看:272
本文介绍了对于给定的遍历gremlin查询,如何在所有访问的节点/边上应用静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在每个节点和边缘上将用户权限标记为(SET基数的)属性.对于给定的遍历gremlin查询,想知道对所有访问的节点/边缘应用has步长的最佳方法是什么.

We are stamping user permission as a property (of SET cardinality) on each nodes and edges. Wondering what is best way to apply the has step on all the visited nodes/edges for a given traversal gremlin query.

就像一个非常简单的遍历查询: //从伦敦希思罗机场(LHR)飞往美国机场的航班

like a very simple travarsal query: // Flights from London Heathrow (LHR) to airports in the USA

g.V().has('code','LHR').out('route').has('country','US').values('code')

使用上述查询在遍历时向所有访问的顶点和边添加has('permission', 'team1').

add has('permission', 'team1') to all the visited vertices and edges while traversal using the above query.

推荐答案

您可以考虑两种方法.

  1. 编写自定义TraversalStrategy
  2. 开发克里姆林宫DSL

对于TraversalStrategy,您将开发类似于SubgraphStrategyPartitionStrategy的工具,这将获取您的用户构建权限,然后在out()/in()类步骤之后自动注入必要的has()步骤.这里的缺点是您的TraversalStrategy必须用JVM语言编写,并且如果使用Gremlin Server,则必须在服务器上安装它.如果您打算以任何方式从客户端配置此TraversalStrategy,则需要构建自定义序列化程序以使其成为可能.

For a TraversalStrategy you would develop one similar to SubgraphStrategy or PartitionStrategy which would take your user permissions on construction and then automatically inject the necessary has() steps after out() / in() sorts of steps. The drawback here is that your TraversalStrategy must be written in a JVM language and if using Gremlin Server must be installed on the server. If you intend to configure this TraversalStrategy from the client-side in any way you would need to build custom serializers to make that possible.

对于DSL,您将为out()/in()各种步骤创建新的导航步骤,并且它们将插入导航步骤和has()步骤的适当组合. DSL方法很不错,因为您可以用任何一种编程语言编写它并且可以使用它,但是它不允许服务器端配置,并且必须始终确保客户端在查询图形时使用DSL.

For a DSL you would create new navigational steps for out() / in() sorts of steps and they would insert the appropriate combination of navigation step and has() step. The DSL approach is nice because you could write it in any programming language and it would work, but it doesn't allow server-side configuration and you must always ensure clients use the DSL when querying the graph.

我们正在将用户权限标记为每个节点和边缘上的属性(具有SET基数).

We are stamping user permission as a property (of SET cardinality) on each nodes and edges.

最后,通过"SET基数"我假设您的意思是多属性.边缘不允许这些,因此您只能在顶点上标记这样的属性.

As a final note, by "SET cardinality" I assume that you mean multi-properties. Edges don't allow for those so you would only be able to stamp such a property on vertices.

这篇关于对于给定的遍历gremlin查询,如何在所有访问的节点/边上应用静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆