简体   繁体   English

对于给定的遍历 gremlin 查询,如何在所有访问过的节点/边上应用静态步骤

[英]How to apply a static has step on all the visited nodes/edges for a given traversal gremlin query

We are stamping user permission as a property (of SET cardinality) on each nodes and edges.我们将用户权限标记为每个节点和边上的属性(SET 基数)。 Wondering what is best way to apply the has step on all the visited nodes/edges for a given traversal gremlin query.想知道在给定遍历 gremlin 查询的所有访问过的节点/边上应用 has 步骤的最佳方法是什么。

like a very simple travarsal query: // Flights from London Heathrow (LHR) to airports in the USA就像一个非常简单的遍历查询:// 从伦敦希思罗机场 (LHR) 到美国机场的航班

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

add has('permission', 'team1') to all the visited vertices and edges while traversal using the above query.在使用上述查询遍历时has('permission', 'team1')has('permission', 'team1')到所有访问过的顶点和边。

There are two approaches you may consider.您可以考虑两种方法。

  1. Write a custom TraversalStrategy编写自定义TraversalStrategy
  2. Develop a Gremlin DSL开发Gremlin DSL

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.对于TraversalStrategy您将开发一个类似于SubgraphStrategyPartitionStrategy ,它们将获取您的用户构建权限,然后在out() / in()类型的步骤之后自动注入必要的has()步骤。 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.这里的缺点是你的TraversalStrategy必须用 JVM 语言编写,如果使用 Gremlin 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.如果您打算以任何方式从客户端配置此TraversalStrategy ,您将需要构建自定义序列化程序以使其成为可能。

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.对于 DSL,您将为out() / in()类型的步骤创建新的导航步骤,并且它们将插入导航步骤和has()步骤的适当组合。 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. DSL 方法很好,因为您可以用任何编程语言编写它并且它可以工作,但它不允许服务器端配置,并且您必须始终确保客户端在查询图形时使用 DSL。

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 .最后一点,“SET cardinality”我假设您的意思是multi-properties Edges don't allow for those so you would only be able to stamp such a property on vertices.边不允许这些,所以你只能在顶点上标记这样的属性。

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

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