orientdb 在某些条件下停止遍历 [英] orientdb stop traverse with some condition

查看:43
本文介绍了orientdb 在某些条件下停止遍历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于此图:第三方可能拥有也可能不拥有参数.

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

参数由上下文代码表示(例如:CREATE VERTEX Parameter SET context='val1', code='val2', value='val3').第三方由类型表示(例如:CREATE VERTEX ThirdParty SET type=7)

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)

从顶点 #40:0 开始,我想检索附加到此节点的给定参数(例如,带有 context='val1' 和 code='val2' 的参数)的值(一个节点可以有不同的参数)).如果该节点不拥有给定的参数,那么我想一一遍历该节点的父节点,直到找到给定参数的值.

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.

我尝试使用此查询:

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)

但问题是,一个第三方可以有多个参数,具有不同的上下文代码,我找不到如何修改while 查询的一部分以与给定的参数(context='val1' 和 code='val2')进行比较.

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').

推荐答案

查询应该是这个:

 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
 )

但是

  1. 你不能使用context"作为属性名,因为它指的是查询上下文,你不会得到你期望的结果

  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.2.19 上发现了一个破坏此查询的错误,我刚刚修复了它并将修复推送到 2.2.x 分支.该修复程序将随 2.2.20 发布.与此同时,几个小时后,您将在此处找到快照 https://oss.sonatype.org/content/repositories/snapshots/com/orientechnologies/orientdb-community/2.2.20-SNAPSHOT/

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/

这篇关于orientdb 在某些条件下停止遍历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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