-
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
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
demos/guru_scripts/docker/tutorial/4.x/script/forEachTest.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,81 @@ | ||
USE GRAPH financialGraph | ||
CREATE OR REPLACE QUERY ForeachTest ( ) SYNTAX V3 { | ||
|
||
ListAccum<UINT> @@listVar = [1, 2, 3]; | ||
SetAccum<UINT> @@setVar = (1, 2, 3); | ||
BagAccum<UINT> @@bagVar = (1, 2, 3); | ||
|
||
SetAccum<UINT> @@set1; | ||
SetAccum<UINT> @@set2; | ||
SetAccum<UINT> @@set3; | ||
|
||
#FOREACH item in collection accumlators variables | ||
S = SELECT tgt | ||
FROM (s:Account) -[e:Transfer]-> (tgt) | ||
ACCUM | ||
@@listVar += e.amount, | ||
@@setVar += e.amount, | ||
@@bagVar += e.amount; | ||
|
||
PRINT @@listVar, @@setVar, @@bagVar; | ||
|
||
//loop element in a list | ||
FOREACH i IN @@listVar DO | ||
@@set1 += i; | ||
END; | ||
|
||
//loop element in a set | ||
FOREACH i IN @@setVar DO | ||
@@set2 += i; | ||
END; | ||
|
||
//loop element in a bag | ||
FOREACH i IN @@bagVar DO | ||
@@set3 += i; | ||
END; | ||
|
||
PRINT @@set1, @@set2, @@set3; | ||
|
||
//show step of loop var | ||
ListAccum<INT> @@st; | ||
FOREACH k IN RANGE[-1,4].STEP(2) DO | ||
@@st += k; | ||
END; | ||
|
||
PRINT @@st; | ||
|
||
ListAccum<INT> @@t; | ||
|
||
//nested loop: | ||
// outer loop iterates 0, 1, 2. | ||
// inner loop iterates 0 to i | ||
FOREACH i IN RANGE[0, 2] DO | ||
@@t += i; | ||
S = SELECT s | ||
FROM (s:Account) | ||
WHERE s.name =="Scott" | ||
ACCUM | ||
FOREACH j IN RANGE[0, i] DO | ||
@@t += j | ||
END; | ||
END; | ||
PRINT @@t; | ||
|
||
MapAccum<STRING,STRING> @@mapVar, @@mapVarResult; | ||
S = SELECT s | ||
FROM (s:Account) | ||
WHERE s.name =="Scott" OR s.name == "Jennie" | ||
ACCUM @@mapVar += (s.name -> s.isBlocked); | ||
|
||
//loop (k,v) pairs of a map | ||
FOREACH (keyI, valueJ) IN @@mapVar DO | ||
@@mapVarResult += (keyI -> valueJ); | ||
END; | ||
|
||
PRINT @@mapVar, @@mapVarResult; | ||
|
||
} | ||
|
||
INSTALL QUERY ForeachTest | ||
|
||
RUN QUERY ForeachTest() |