orientdb stop traverse with some condition

情到浓时终转凉″ 提交于 2019-12-25 12:23:13

问题


Given this graph: A third party may or not own a parameter.

A Parameter is represented by a context, code and value (EX: CREATE VERTEX Parameter SET context='val1', code='val2', value='val3'). A ThirdParty is represented by a type (Ex: CREATE VERTEX ThirdParty SET type=7)

Starting from vertex #40:0, i would like to retrieve the value of a given parameter(example, parameter with context='val1' and code='val2') attached to this node (a node can have different parameters). If the node doesn't own the given parameter, then i would like to traverse the parents of this node one by one till i find a value for the given parameter.

I tried using this query:

SELECT parameter.value FROM (MATCH {class:ThirdParty, 
          where: (type = 7)}.in('parent_of')
          {while: (out('owns').size() == 0), 
          where: (out('owns').size() > 0)}.out('owns')
          {as: parameter} RETURN parameter)

but the problem is, a ThirdPary can have multiple Parameters, with different context and code, and i can't find how to modify the while part in the query to compare with the given parameter (context='val1' and code='val2').


回答1:


The query should be this one:

 SELECT parameter.value FROM (
   MATCH 
      {class:ThirdParty, where: (type = 7)}
      .in('parent_of')
      {
        while: (
           not (
             out('owns').context contains "val1"
             AND
             out('owns').code contains "val2"
           )
        ), 
        where: (
          out('owns').context contains "val1"
          AND
          out('owns').code contains "val2"
        )
      }.out('owns')
      {as: parameter, where:(code = "val2" and context = "val1")} 
   RETURN parameter
 )

BUT

  1. you cannot use "context" as a property name, because it refers to the query context and you won't have the result you expect

  2. I found a bug on 2.2.19 that breaks this query, I just fixed it and pushed the fix on 2.2.x branch. The fix will be released with 2.2.20. In the meantime, in a few hours you'll find the snapshot here https://oss.sonatype.org/content/repositories/snapshots/com/orientechnologies/orientdb-community/2.2.20-SNAPSHOT/



来源:https://stackoverflow.com/questions/43767480/orientdb-stop-traverse-with-some-condition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!