-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
demos/guru_scripts/docker/tutorial/4.x/script/whileTest.gsql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
USE GRAPH financialGraph | ||
CREATE OR REPLACE QUERY WhileTest (VERTEX<Account> seed) SYNTAX V3 { | ||
//mark if a node has been seen | ||
OrAccum @visited; | ||
//empty vertex set var | ||
reachable_vertices = {}; | ||
//declare a visited_vertices var, annotated its type | ||
//as ANY type so that it can take any vertex | ||
visited_vertices (ANY) = {seed}; | ||
|
||
// Loop terminates when all neighbors are visited | ||
WHILE visited_vertices.size() !=0 DO | ||
//s is all neighbors of visited_vertices | ||
//which have not been visited | ||
visited_vertices = SELECT s | ||
FROM (:visited_vertices)-[:transfer]->(s) | ||
WHERE s.@visited == FALSE | ||
POST-ACCUM | ||
s.@visited = TRUE; | ||
|
||
reachable_vertices = reachable_vertices UNION visited_vertices; | ||
END; | ||
|
||
PRINT reachable_vertices; | ||
|
||
//reset vertex set variables | ||
reachable_vertices = {}; | ||
visited_vertices (ANY) = {seed}; | ||
|
||
|
||
//clear the visited flag | ||
S1 = SELECT s | ||
FROM (s:Account) | ||
ACCUM s.@visited = FALSE; | ||
|
||
// Loop terminates when condition met or reach 2 iterations | ||
WHILE visited_vertices.size() !=0 LIMIT 2 DO | ||
visited_vertices = SELECT s | ||
FROM (visited_vertices)-[:transfer]-> (s) | ||
WHERE s.@visited == FALSE | ||
POST-ACCUM | ||
s.@visited = TRUE; | ||
|
||
reachable_vertices = reachable_vertices UNION visited_vertices; | ||
END; | ||
|
||
PRINT reachable_vertices; | ||
} | ||
|
||
|
||
INSTALL QUERY WhileTest | ||
|
||
RUN QUERY WhileTest("Scott") |