问题
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.
回答1:
Change the line:
.select('x').unfold()
To:
.cap('x').unfold()
来源:https://stackoverflow.com/questions/55344199/gremlin-query-is-returning-no-results-when-part-of-the-query-returns-nothing