Skip to content

Commit

Permalink
Create caseWhenTest.gsql
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxiw authored Jan 21, 2025
1 parent 4e64be4 commit 1aa125d
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions demos/guru_scripts/docker/tutorial/4.x/script/caseWhenTest.gsql
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()

0 comments on commit 1aa125d

Please sign in to comment.