-
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
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
demos/guru_scripts/docker/tutorial/4.x/script/caseWhenTest.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,66 @@ | ||
USE GRAPH financialGraph | ||
CREATE OR REPLACE QUERY CaseWhenTest () SYNTAX V3{ | ||
|
||
SumAccum<INT> @@isBlocked; | ||
SumAccum<INT> @@unBlocked; | ||
SumAccum<INT> @@others; | ||
|
||
SumAccum<INT> @@isBlocked2; | ||
SumAccum<INT> @@unBlocked2; | ||
SumAccum<INT> @@others2; | ||
|
||
|
||
//case-when in a query block | ||
S1 = SELECT a | ||
FROM (a:Account) | ||
ACCUM | ||
//if-else semantic: within query block, statement | ||
//does not need a semicolon to end. | ||
CASE | ||
WHEN a.isBlocked THEN @@isBlocked += 1 | ||
WHEN NOT a.isBlocked THEN @@unBlocked += 1 | ||
ELSE @@others += 1 | ||
END; | ||
|
||
|
||
PRINT @@isBlocked, @@unBlocked, @@others; | ||
|
||
S2 = SELECT a | ||
FROM (a:Account) | ||
ACCUM | ||
//switch semantic: within query block, statement | ||
//does not need a semicolon to end. | ||
CASE a.isBlocked | ||
WHEN TRUE THEN @@isBlocked2 += 1 | ||
WHEN FALSE THEN @@unBlocked2 += 1 | ||
ELSE @@others2 += 1 | ||
END; | ||
|
||
PRINT @@isBlocked2, @@unBlocked2, @@others2; | ||
|
||
STRING drink = "Juice"; | ||
SumAccum<INT> @@calories = 0; | ||
|
||
//if-else version. Top-statement level. Each statement | ||
//needs to end by a semicolon, including the “END”. | ||
CASE | ||
WHEN drink == "Juice" THEN @@calories += 50; | ||
WHEN drink == "Soda" THEN @@calories += 120; | ||
ELSE @@calories = 0; // Optional else-clause | ||
END; | ||
// Since drink = "Juice", 50 will be added to calories | ||
|
||
//switch version. Top-statement level. Each statement | ||
//needs to end by a semicolon, including the “END”. | ||
CASE drink | ||
WHEN "Juice" THEN @@calories += 50; | ||
WHEN "Soda" THEN @@calories += 120; | ||
ELSE @@calories = 0; // Optional else-clause | ||
END; | ||
|
||
PRINT @@calories; | ||
} | ||
|
||
INSTALL QUERY CaseWhenTest | ||
|
||
RUN QUERY CaseWhenTest() |