[Beginner] Is there a direct way to iterate over all the vertexes of certain type?

Hey guys, I’m a newbie to graph databases. Currently, I am learning GSQL by trying simple applications like finding 2-hop friends for each person in a graph. However, after reading some GSQL examples, I still don’t know how to iterate over all the vertexes so that I can pass each of them as a parameter to the query khop (which is provided by the tigergraph benchmark on Github). I come up with a very naive and stupid way to do this(which is slow):

create query fof(STRING filepath) for graph social{
	SetAccum<vertex<person>> @@allperson, @@result;
	FILE f1 (filepath);
	all = {person.*};
	
	all = select s from all:s accum @@allperson += s;
	foreach p in @@allperson do
		@@result =  khop(p, 2);
		f1.println(p, @@result);
	end;
}

Is there a more direct way?

1 Like

Hi Ziliang,

By iterate over a SetAccum, each khop execution will be sequential. To parallelize this process you can directly call the subquery from accum clause.

For example:

create query fof(STRING filepath) for graph social{

FILE f1 (filepath);

all = {person.*};

all = select s from all:s accum f1.println(s, khop(s, 2)); // or you can directly pass the file object to the sub query and print in the subquery to avoid returning the vertex set.

}

Hope this solves your problem.

Thanks.