The GSQL query below calculates the reachable DAG (Direct Acyclic Graph) for a person node, namely, all the persons that are reachable as direct or indirect friends of a given person, for any level of indirection (unlimited hops). What I need now is to present the result as a JSON hierarchy that shows the nested levels of indirect relationships in the graph, so that for every person in the result graph, his or her direct friends are shown as directly nested JSON structures. In Gremlin, that query can be written with an explicit tree accumulator: repeat(out(“friend”)).until(__.not(outE(“friend”))).emit().tree().
– How do we modify the GSQL query below to produce the JSON tree for the resulting DAG?
Thanks !!
CREATE QUERY reachableDAG(VERTEX p) FOR GRAPH Social {
SetAccum @@reachableEdges;
OrAccum @chosenEdge
Current= {p};
WHILE (Current.size() > 0) DO
Current = SELECT reachablePerson
FROM Current:s -(Friend:e) -> reachablePerson
WHERE e.@chosenEdge == false
ACCUM e.@chosenEdge = true
@@reachableEdges += e;
END;
PRINT @@reachableEdges;
}