当部分查询不返回任何结果时,Gremlin 查询不返回任何结果

我有一个 gremlin 查询,可以找到我想要存档的顶点,但它返回一个空数组。


我的图表的布局方式是一个顶点可以有多个父母和孩子。当一个顶点被归档时,它需要归档所有受影响的后代,这些后代将被这个过程“孤立”。如果任何后代有返回中心顶点的路径,那么它不应该存档它,因为它不会被“孤立”


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.

当它发现一些后代有返回中心顶点的路径而不经过原始顶点时,它就会工作并返回它应该返回的所有结果。但是,如果它找不到任何具有返回路径的后代,那么理论上它应该只返回所有后代。相反,它返回一个空数组。我的猜测是它在遍历的那个阶段之后卡住了,因为它什么也没找到,因此无法继续进行任何其他操作。


如果在那个阶段什么也没找到,我该如何归还所有后代?


有关图表的示例,请参阅我之前的问题。


暮色呼如
浏览 115回答 1
1回答

哔哔one

更改行:.select('x').unfold()至:.cap('x').unfold()
打开App,查看更多内容
随时随地看视频慕课网APP