当查询的一部分不返回任何内容时,Gremlin查询不返回任何结果 [英] Gremlin query is returning no results when part of the query returns nothing

查看:82
本文介绍了当查询的一部分不返回任何内容时,Gremlin查询不返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gremlin查询,该查询找到了我要存档的顶点,但是它返回一个空数组.

I have a gremlin query which finds the vertices I want to archive but it is returning an empty array.

我的图的布局方式是,一个顶点可以有多个父级和子级.存档顶点时,需要将其所有受影响的后代存档,这些后代将被此过程孤立".如果任何后代具有返回中心顶点的路径,则不应将其存档,因为它不会被孤立"

My graph is laid out in a way where a vertex can have multiple parents and children. When a vertex is archived then it needs to archive all of it's affected descendants that would be 'orphaned' by this process. If any of the descendants have a path back to a central vertex then it shouldn't archive it because it won't be 'orphaned'

g.V(itemId)                                            // Find the item to delete.
  .union(                                              // Start a union to return
    g.V(itemId),                                       // both the item 
    g.V(itemId)                                        // and its descendants.
      .repeat(__.inE('memberOf').outV().store('x'))    // Find all of its descendants.
      .cap('x').unfold()                               // Unfold them.
      .where(repeat(out('memberOf')                    // Check each descendant
        .where(hasId(neq(itemId))).simplePath())       // to see if it has a path back that doesn't go through the original vertex
        .until(hasId(centralId)))                      // that ends at the central vertex .
      .aggregate('exception')                          // Aggregate these together.
      .select('x').unfold()                            // Get all the descendants again.
      .where(without('exception')))                    // Remove the exceptions.
  .property('deleted', true)                           // Set the deleted property.
  .valueMap(true)                                      // Rteurn the results.

当发现某些后代具有不经过原始顶点的返回中心顶点的路径时,它将起作用并返回所有应有的结果.但是,如果找不到路径返回的任何后代,则从理论上讲,它应该只返回所有后代.相反,它返回一个空数组.我的猜测是,在遍历的那个阶段之后它被卡住了,因为它什么也没发现,因此无法继续前进.

When it finds that some of the descendants have path(s) back to the central vertex that don't go through the original vertex then it works and returns all the results that it should. However, if it can't find any descendants with paths back then in theory it should just return all of the descendants. Instead, it is returning an empty array. My guess is that it's getting stuck after that stage of the traversal because it is finding nothing and can therefore not move on to anything else.

如果在那个阶段什么都没找到,我如何返回所有后代?

How can I return all of the descendants if it finds nothing at that stage?

有关该图的示例,请参见

For an example of the graph please see my previous question.

推荐答案

更改行:

.select('x').unfold()

收件人:

.cap('x').unfold()

这篇关于当查询的一部分不返回任何内容时,Gremlin查询不返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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