I have a tree without predefined depth and amount of nodes, like that:
Every node has an edge of the same type to its parent of the same type and a boolean parameter - 0 or 1.
I need to get all of the nodes that have it set to 1 and all of their parents should have it set to 1 as well.
The start of the route is always A1.
Thus, based on the example above, the result should be: A1, C1, F1, G1.
I saw some examples here:
https://docs.tigergraph.com/intro/gsql-102/multiple-hop-pattern
but it answers my questions partly and it’s actually hard to get how to do it.
Basically, I need to:
-
Query N-hop with condition.
-
Get all of the nodes that are found along the way.
Hi Oleg,
Thanks for your question. Please find the query example below:
CREATE QUERY test4(vertex inputVertex) FOR GRAPH MyGraph syntax(“v2”) {
SetAccum<vertex> @@vertex_set;
start = {inputVertex};
start = select t from start:s- (_>*)-:t
where t.boolAttr == 1
accum @@vertex_set += t;
print @@vertex_set;
}
However, for better performance, it is recommended to use syntax v1
CREATE QUERY test4(vertex inputVertex) FOR GRAPH MyGraph{
SetAccum<vertex> @@vertex_set;
start = {inputVertex};
while(start.size() > 0) do
start = select t from start:s- (:e)-:t
where t.boolAttr == 1
accum @@vertex_set += t;
end;
print @@vertex_set;
}
Please let me know if you have any questions.
Thanks.
Thanks for your help!
I still have 2 questions:
- How to do it when my boolean parameter is set on edge instead of vertex in case of v2 syntax?
start = select t from start:s- (_>*)-:t
I don’t see here a way to specify * edge as a field (it’s not allowed according to the docs) and then to add a condition to it.
- In the output I see only array of ids to vertices. How can I output actual vertices with their parameters?
Is there a way to have an accumulator not just as a vertex but as an array of vertices so I can output it and see the vertices instead of their ids?