I’m writing a number of queries that will return quickly most of the time. However in certain cases, because of the structure of the graph (high degree nodes, etc) they will time out.
When a query times out, I’m interested in returning partial results. Even if the full results could not be found, partial results may still be useful for a user. As an example I’ll give a simplified query:
CREATE QUERY searchNeighbors(Vertex seed, String searchTerm, Int skip=0, Int lim=10) FOR GRAPH test SYNTAX v2 {
SetAccum<Vertex> @@hits;
OrAccum @visited = false;
SumAccum<int> @@loop=0;
MinAccum<Int> @depth;
// mark seed visited
Frontier (ANY) = {seed};
Frontier = SELECT v
FROM Frontier:v
ACCUM v.@visited += true;
// breadth-first search
WHILE (@@hits.size() < skip + lim) DO
@@loop += 1;
Frontier = SELECT v
FROM Frontier:u-((_|_>):e)-ANY:v
WHERE v.@visited == false
ACCUM v.@visited += true, v.@depth += @@loop
POST-ACCUM
CASE WHEN v.name == searchTerm THEN @@hits += v END;
END;
results (ANY) = @@hits;
// get results in BFS order
results = SELECT u FROM results:u ORDER BY u.@depth ASC, getvid(u) DESC LIMIT lim OFFSET skip;
print results;
}
What I would like to do is break out of the WHILE loop if the query goes on too long, and take whatever is in @@hits and proceed to the next stage of the query.
What’s the best way to do this in GSQL?